task-stream is a global 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; use task_stream::{TaskPoint, TASKS};
async fn asyncmain() { task::spawn(async { let mut stream = TASKS.stream(); while let Some(task) = stream.next().await { match task { TaskPoint::Sync(f) => { std::thread::spawn(f); } TaskPoint::Async(fut) => { task::spawn(fut); } } } }); let clock = TASKS.clock(); loop { task::sleep(Duration::frommillis(100)).await; clock.tick(100); } } ```