executor-core
Write async libraries without choosing a runtime.
Your users should decide whether to use tokio, async-std, or any other runtime. Not you.
How It Works
Instead of hard-coding tokio::spawn
, accept an executor parameter:
use Executor;
pub async
Users call it with their runtime:
// tokio users
let runtime = new?;
let sum = parallel_sum.await;
// async-executor users
let executor = new;
let sum = parallel_sum.await;
Quick Start
Library authors:
[]
= "0.2"
App developers:
[]
= { = "0.2", = ["tokio"] }
API
Two traits:
Executor
- ForSend
futuresLocalExecutor
- For non-Send
futures
Both return async_task::Task
:
let task = executor.spawn;
let result = task.await; // Get result
task.cancel.await; // Cancel task
task.detach; // Run in background
Supported Runtimes
Runtime | Feature |
---|---|
tokio | "tokio" |
async-executor | "async-executor" |
Web/WASM | "web" |
License
MIT