task-stream

Crates.iotask-stream
lib.rstask-stream
version0.3.7
sourcesrc
created_at2021-03-22 13:58:02.652094
updated_at2022-08-08 03:22:54.644684
descriptiona global task executor, run in `no_std`.
homepagehttps://blog.crise.cn
repositoryhttps://github.com/rise0chen/task-stream.git
max_upload_size
id372149
size34,181
Rise Chen (rise0chen)

documentation

https://docs.rs/task-stream

README

Task-Stream

task-stream is a global task executor, can run in no_std.

Usage

spawn

async fn async_task() {
    println!("async_task.");
}
task_stream::spawn(async_task());

executor

without async executor

use core::time::Duration;
use std::thread;

fn main() {
    let stream = task_stream::stream();
    loop {
        while let Some(task) = stream.get_task() {
            task.run();
        }
        thread::sleep(Duration::from_millis(100));
    }
}

use async executor

use async_std::prelude::*;
use async_std::task;

fn main() {
    task::spawn(async {
        let mut stream = task_stream::stream();
        while let Some(task) = stream.next().await {
            task.run();
        }
    });
}
Commit count: 12

cargo fmt