Task Execution Queue

English | 简体中文

Task Execution Queue A task execution queue. Can limit the number of concurrent tasks and execution order of the same type of tasks can be controlled. Generally, asynchronous tasks can be executed directly using Tokio or async-std; However, in some special business scenarios, when we need to execute tasks in batches and control the concurrent number of tasks, using spawn() directly can easily lead to excessive load and exhaustion of resources such as CPU or memory; This Crate is developed to solve such problems.

Features

Plan

Examples

```rust fn main() { use asyncstd::task::spawn; use rustbox::taskexecqueue::{init_default, default, SpawnDefaultExt};

let task_runner = init_default();
let root_fut = async move {
    spawn(async {
        //start executor
        task_runner.await;
    });

    //execute task ...
    let _ = async {
        println!("hello world!");
    }.spawn().await;

    default().flush().await;
};
async_std::task::block_on(root_fut);

}

```

```rust fn main() { use asyncstd::task::spawn; use rustbox::taskexecqueue::{Builder, SpawnExt}; let (exec, taskrunner) = Builder::default().workers(10).queuemax(100).build(); let rootfut = async move { spawn(async { //start executor taskrunner.await; });

    //execute task and return result...
    let res = async {
        "hello world!"
    }.spawn(&exec).result().await;
    println!("result: {:?}", res.ok());

    exec.flush().await;
};
async_std::task::block_on(root_fut);

}

```

```rust fn main() { use asyncstd::task::spawn; use rustbox::taskexecqueue::{Builder, SpawnExt};

let (exec, task_runner) =
    Builder::default().workers(10).queue_max(100).group().build::<&str>();
let root_fut = async move {
    spawn(async {
        //start executor
        task_runner.await;
    });

    //execute task ...
    let _res = async move {
        println!("hello world!");
    }.spawn(&exec).group("g1").await;

    let res = async move {
        "hello world!"
    }.spawn(&exec).group("g1").result().await;
    println!("result: {:?}", res.ok());

    exec.flush().await;
    println!("exec.actives: {}, waitings: {}, completeds: {}", exec.active_count(), exec.waiting_count(), exec.completed_count());
};
async_std::task::block_on(root_fut);

}

```

More Examples