Crates.io | cbsk_run |
lib.rs | cbsk_run |
version | 2.0.6 |
source | src |
created_at | 2023-12-13 08:07:24.749566 |
updated_at | 2024-11-15 03:33:35.5628 |
description | cbsk_run is async pool tool |
homepage | |
repository | https://github.com/lifeRobot/cbsk/tree/master/libs/cbsk_run |
max_upload_size | |
id | 1067761 |
size | 5,298 |
cbsk_run is async pool tool
the main functions include async pool and signal::run
1.80.0
Cargo.toml file :
cbsk_base = { version = "2.0.6" }
cbsk_run = { version = "2.0.6" }
main.rs file :
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;
}
})
}
running results :
E:\work\github\rust\cbsk_test>cargo run
Compiling cbsk_run v0.1.0 (E:\work\github\rust\cbsk\libs\cbsk_run)
Compiling cbsk_test v0.1.0 (E:\work\github\rust\cbsk_test)
Finished dev [unoptimized + debuginfo] target(s) in 4.21s
RunningE:\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>