English | 简体中文
Task Executor Task executors that control the number of parallel executions. Usually, ordinary asynchronous tasks can be executed directly using Tokio or async-std; however, in some special business scenarios, we need to perform a certain type of tasks in batches, and control the number of concurrent tasks of this type. Using spawn() directly can easily lead to excessive load and exhaustion of resources such as CPU or memory. this executor was developed to solve such problems.
quick start ```rust fn main() { use asyncstd::task::spawn; use rustbox::taskexecutor::{initdefault, default, SpawnDefaultExt};
let taskrunner = initdefault(); let global = async move{ spawn(async { //start executor task_runner.await; }); //execute future ... let _ = async { println!("hello world!"); }.spawn().await;
default().flush().await;
}; asyncstd::task::blockon(global); }
```
execute and return result ```rust fn main() { use asyncstd::task::spawn; use rustbox::taskexecutor::{Builder, SpawnExt}; let (exec, taskrunner) = Builder::default().workers(10).queuemax(100).build(); let global = async move{ spawn(async { //start executor taskrunner.await; }); //execute future and return result... let res = async { "hello world!" }.spawn(&exec).result().await; println!("return result: {:?}", res.ok());
exec.flush().await;
}; asyncstd::task::blockon(global); }
```