Expand description
§ARCHIVED ARCHIVED ARCHIVED
This crate is archived and will not be updated.
The code is now at
safina::executor in the
safina crate.
§safina-executor
An async executor.
It is part of safina, a safe async runtime.
§Features
- Spawn async tasks to execute on a threadpool.
- Schedule closures or
FnOnceto run on a separate thread pool for blocking jobs. - Supports multiple executors.
forbid(unsafe_code)- Depends only on
std - Good test coverage (100%)
§Limitations
- Allocates memory
- Not optimized
§Documentation
https://docs.rs/safina-executor
§Examples
let executor = safina_executor::Executor::default();
let (sender, receiver) = std::sync::mpsc::channel();
executor.spawn(async move {
sender.send(()).unwrap();
});
receiver.recv().unwrap();let result = safina_executor::block_on(async {
prepare_request().await?;
execute_request().await
})?;let result = safina_executor::schedule_blocking(|| {
read_file1()?;
read_file2()
}).async_recv().await.unwrap()?;§Alternatives
async-executor- Popular
- Dependencies have some
unsafecode
futures-executor- Very popular
- Full of
unsafe
tokio-executor- Very popular
- Fast
- Internally complicated
- Full of
unsafe
executors- Dependencies have lots of
unsafecode
- Dependencies have lots of
bastion-executor- Lots of
unsafecode
- Lots of
rayon_core- Generous amounts of
unsafecode
- Generous amounts of
pollster- Minimal
- Has a little
unsafecode
lelet- Automatically scales worker thread pool
- Lots of
unsafecode
fibers- Dependencies are full of unsafe
nostd_async- Has some
unsafecode
- Has some
embedded-executor- Generous amounts of
unsafecode
- Generous amounts of
spin_on- Minimal
pastsswitchyard- Lots of
unsafecode
- Lots of
sealrsrusty_pool- Automatically adjusts thread pool
- Dependencies are full of unsafe
§Changelog
- v0.3.3 - Eliminate spurious “resumed after completion” worker thread panics.
- v0.3.2 - Re-export
safina_sync::Receiverandsafina_threadpool::NewThreadPoolError. - v0.3.1 - Use
safina-asyncv0.2.1. - v0.3.0 -
schedule_blockingto return newsafina_sync::Receiver. - v0.2.1 - Update docs.
- v0.2.0
Executor::newandExecutor::with_nameto returnResult.- Upgrade to
safina-threadpoolv0.2.0.
- v0.1.7 -
block_onfunctions to take futures that are notSend. - v0.1.6 - Fix deadlock in
block_onandblock_on_unpinwhen task is awakened a second time. - v0.1.5 - Support stable Rust! Needs 1.51+.
- v0.1.4 - Add
schedule_blockingandExecutor::schedule_blocking - v0.1.3
- Removed global executor. Users must explicitly create executor.
- Removed dependency on unstable
OnceCell. - Uses
safina_threadpoolinternally.
- v0.1.2 - Let callers pass futures to
spawnandblock_onwithout usingBox::pin. Addspawn_unpinandblock_on_unpinfor folks who need to avoid allocating. so callers don’t have to. - v0.1.1 - Fix badge and update readme
- v0.1.0 - Renamed from
safina
§TO DO
- Add a stress test
- Add a benchmark. See benchmarks in https://crates.io/crates/executors
- Add an
#[async_main]macro - Look into using
flumeto eliminate the receiver mutex and reduce contention.
§Release Process
- Edit
Cargo.tomland bump version number. - Run
./release.sh
Structs§
- Executor
- A collection of threads for executing tasks and blocking jobs.
- Receiver
- The receiving half of a channel. This half can only be owned by one thread.
- Thread
Executor Guard - Guard returned by
set_thread_executor.
Enums§
Functions§
- block_
on - Executes the future on the current thread and returns its result.
- block_
on_ unpin - Executes the future on the current thread and returns its result.
- get_
thread_ executor - Gets the
Executorfrom thread-local storage. - schedule_
blocking - Schedules
functo run on any available thread in the blocking thread pool. - set_
thread_ executor - Sets
executoras theExecutorfor the current thread, saving it to thread-local storage. - spawn
- Creates a new task to execute
futand schedules it for immediate execution. - spawn_
unpin - Creates a new task to execute
futand schedules it for immediate execution.