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 |
|
#580 在 异步
每月 376 次下载
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 worldE:\work\github\rust\cbsk_test>
依赖项
~2.5–8.5MB
~61K SLoC