#async-pool #signal #cbsk #run #tool #function

cbsk_run

cbsk_run 是异步池工具

15 个版本 (9 个稳定版本)

新版本 2.0.0 2024 年 8 月 21 日
1.3.11 2024 年 8 月 19 日
1.3.10 2024 年 7 月 26 日
0.1.11 2024 年 4 月 2 日
0.1.5 2023 年 12 月 20 日

#580异步

Download history 235/week @ 2024-05-08 161/week @ 2024-05-15 36/week @ 2024-05-22 158/week @ 2024-06-05 3/week @ 2024-06-12 140/week @ 2024-06-26 15/week @ 2024-07-03 109/week @ 2024-07-17 203/week @ 2024-07-24 41/week @ 2024-07-31 130/week @ 2024-08-14

每月 376 次下载

MIT/Apache

27KB
395

cbsk_run 是异步池工具
主要功能包括异步池和 signal::run

支持 Rust 的最低版本

1.80.0

signal::run 示例

Cargo.toml 文件

cbsk_base = { version = "2.0.0" }
cbsk_run = { version = "2.0.0" }

main.rs 文件

use std::time::Duration;
use cbsk_base::{anyhow, tokio};
use cbsk_base::tokio::task::JoinHandle;

#[tokio::main]
async fn main() {
    cbsk_run::run::signal::run(runnable()).await
}

fn runnable() -> anyhow::Result<Vec<JoinHandle<()>>> {
    Ok(vec![hello_world(), say_hi()])
}

fn hello_world() -> JoinHandle<()> {
    tokio::spawn(async {
        loop {
            println!("hello world");
            tokio::time::sleep(Duration::from_secs(1)).await;
        }
    })
}

fn say_hi() -> JoinHandle<()> {
    tokio::spawn(async {
        loop {
            println!("hi!");
            tokio::time::sleep(Duration::from_secs(2)).await;
        }
    })
}

运行结果

E:\work\github\rust\cbsk_test>cargo run
编译 cbsk_run v0.1.0 (E:\work\github\rust\cbsk\libs\cbsk_run)
编译 cbsk_test v0.1.0 (E:\work\github\rust\cbsk_test)
已完成 dev [未优化 + 调试信息] 目标(s) 在 4.21 秒
运行 E:\work\cache\rust\github\target\debug\cbsk_test.exe
hello world
hi!
hello world
hello world
hi!
hello world
hello world
hi!
hello world
hello world
hi!
hello world
hello world
hi!
hello world
hello world
hi!
hello world
hi!
hello world
hello world
hello world
hi!
hello world

E:\work\github\rust\cbsk_test>

依赖项

~2.5–8.5MB
~61K SLoC