task-stream is a gobal task spawner, can run in no_std
.
It support the timer tasks, sync/async task.
It design for crate-creator. In third-party crate, can spawn a sub-task without care which executor user's app use.
```rust use task_stream::{TaskType, TASKS};
fn synctask() { println!("synctask."); } async fn asynctask() { println!("asynctask."); } TASKS.addtask(TaskType::Interval(1000), synctask); TASKS.addtask(TaskType::Timeout(1000), || { println!("hello world."); }); TASKS.addasynctask(TaskType::Timeout(1000), Box::pin(asynctask())); let a = 1; TASKS.addasynctask( TaskType::Timeout(1000), Box::pin(async move { println!("hello async, {}.", a); }), ); ```
```rust use asyncstd::prelude::*; use asyncstd::task; use core::time::Duration;
async fn asyncmain() { task::spawn(async { let mut stream = TASKS.stream(); while let Some(fut) = stream.next().await { task::spawn(fut); } }); let clock = TASKS.clock(); loop { task::sleep(Duration::fromsecs(10)).await; clock.tick(100); } } ```