Crate safina_executor[−][src]
An async executor.
It is part of safina
, a safe async runtime.
Features
- Spawn async tasks to execute on a threadpool.
- Schedule closures or
FnOnce
to 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() }).await?;
Alternatives
async-executor
- Popular
- Dependencies have some
unsafe
code
futures-executor
- Very popular
- Full of
unsafe
tokio-executor
- Very popular
- Fast
- Internally complicated
- Full of
unsafe
executors
- Dependencies have lots of
unsafe
code
- Dependencies have lots of
bastion-executor
- Lots of
unsafe
code
- Lots of
rayon_core
- Generous amounts of
unsafe
code
- Generous amounts of
pollster
- Minimal
- Has a little
unsafe
code
lelet
- Automatically scales worker thread pool
- Lots of
unsafe
code
fibers
- Dependencies are full of unsafe
nostd_async
- Has some
unsafe
code
- Has some
embedded-executor
- Generous amounts of
unsafe
code
- Generous amounts of
spin_on
- Minimal
pasts
switchyard
- Lots of
unsafe
code
- Lots of
sealrs
rusty_pool
- Automatically adjusts thread pool
- Dependencies are full of unsafe
Changelog
- v0.1.6 - Fix deadlock in
block_on
andblock_on_unpin
when task is awakened a second time. - v0.1.5 - Support stable Rust! Needs 1.51+.
- v0.1.4 - Add
schedule_blocking
andExecutor::schedule_blocking
- v0.1.3
- Removed global executor. Users must explicitly create executor.
- Removed dependency on unstable
OnceCell
. - Uses
safina_threadpool
internally.
- v0.1.2 - Let callers pass futures to
spawn
andblock_on
without usingBox::pin
. Addspawn_unpin
andblock_on_unpin
for 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
- DONE - Implement
spawn
- DONE - Implement
block_on
- DONE - Implement
increase_threads_to
- DONE - Drop finished futures
- DONE - Handle task panic
- DONE - Add
stop_threads
,allow_threads
, andincrease_threads_to
. - DONE - Add tests
- DONE - Add docs
- DONE - Publish on crates.io
- DONE - Add an
#[async_test]
macro - DONE - Build with Rust
stable
. - Add a stress test
- Add a benchmark. See benchmarks in https://crates.io/crates/executors
- Add an
#[async_main]
macro
Release Process
- Edit
Cargo.toml
and bump version number. - Run
./release.sh
Structs
Executor | A collection of threads for executing tasks and blocking jobs. |
ThreadExecutorGuard | Guard returned by |
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 |
schedule_blocking | Schedules |
set_thread_executor | Sets |
spawn | Creates a new task to execute |
spawn_unpin | Creates a new task to execute |