#task #executor #async-executor #stream #spawn

task-stream

一个全局任务执行器,在 no_std 中运行

13个版本

0.3.7 2022年8月8日
0.3.6 2022年4月24日
0.3.3 2021年7月27日
0.3.2 2021年3月26日
0.1.2 2021年3月23日

异步类别中排名2216

Download history 23/week @ 2024-04-20 21/week @ 2024-04-27 18/week @ 2024-05-04 23/week @ 2024-05-11 16/week @ 2024-05-18 23/week @ 2024-05-25 26/week @ 2024-06-01 13/week @ 2024-06-08 14/week @ 2024-06-15 25/week @ 2024-06-22 5/week @ 2024-06-29 2/week @ 2024-07-06 26/week @ 2024-07-13 18/week @ 2024-07-20 43/week @ 2024-07-27 12/week @ 2024-08-03

每月下载量99
9 crate 使用(3个直接使用)

自定义许可证

12KB
152

Task-Stream

task-stream是一个全局任务执行器,可以在no_std中运行。

用法

spawn

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

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_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();
        }
    });
}

依赖项

~0.7–1MB
~18K SLoC