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

cbsk_run

cbsk_run is async pool tool

8 releases (2 stable)

new 1.2.0 May 14, 2024
1.1.0 May 9, 2024
0.1.11 Apr 2, 2024
0.1.10 Mar 22, 2024
0.1.5 Dec 20, 2023

#579 in Asynchronous

Download history 151/week @ 2024-02-19 314/week @ 2024-02-26 13/week @ 2024-03-04 7/week @ 2024-03-11 128/week @ 2024-03-18 153/week @ 2024-04-01 9/week @ 2024-04-08 148/week @ 2024-05-06

149 downloads per month

MIT/Apache

20KB
280 lines

cbsk_run is async pool tool
the main functions include async pool and signal::run

async pool example

Cargo.toml file :

cbsk_base = { version = "1.2.0" }
cbsk_run = { version = "1.2.0" }

main.rs file :

use std::time::Duration;
use cbsk_base::tokio;

#[tokio::main]
async fn main() {
    // println hello world
    cbsk_run::async_pool::push(async {
        loop {
            println!("hello world");
            tokio::time::sleep(Duration::from_secs(1)).await;
        }
    });

    // println hi
    cbsk_run::async_pool::push(async {
        loop {
            println!("hi!");
            tokio::time::sleep(Duration::from_secs(2)).await;
        }
    });

    // wait for async to end
    cbsk_run::async_pool::listener().await.unwrap();
}

signal::run example

Cargo.toml file :

cbsk_base = { version = "1.2.0" }
cbsk_run = { version = "1.2.0" }

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
Running 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>

Dependencies

~0–6MB
~19K SLoC