task-stream 0.2.0

a gobal task spawner, run in `no_std`.
docs.rs failed to build task-stream-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: task-stream-0.3.7

Task-Stream

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.

Usage

third-party carte

use task_stream::{TaskType, TASKS};

fn sync_task() {
    println!("sync_task.");
}
async fn async_task() {
    println!("async_task.");
}
TASKS.add_task(TaskType::Interval(1000), sync_task);
TASKS.add_task(TaskType::Timeout(1000), || {
    println!("hello world.");
});
TASKS.add_async_task(TaskType::Timeout(1000), Box::pin(async_task()));
let a = 1;
TASKS.add_async_task(
    TaskType::Timeout(1000),
    Box::pin(async move {
        println!("hello async, {}.", a);
    }),
);

user'a app

use async_std::prelude::*;
use async_std::task;
use core::time::Duration;
use task_stream::{TaskPoint, TASKS};

async fn async_main() {
    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::from_millis(100)).await;
        clock.tick(100);
    }
}