14 releases

0.3.3 Mar 27, 2022
0.3.2 Mar 24, 2022
0.2.1 Feb 25, 2022
0.1.7 Jun 25, 2021
0.1.4 Dec 29, 2020

#212 in Asynchronous

Download history 25/week @ 2022-10-12 18/week @ 2022-10-19 52/week @ 2022-10-26 67/week @ 2022-11-02 49/week @ 2022-11-09 51/week @ 2022-11-16 20/week @ 2022-11-23 35/week @ 2022-11-30 80/week @ 2022-12-07 27/week @ 2022-12-14 54/week @ 2022-12-21 39/week @ 2022-12-28 7/week @ 2023-01-04 30/week @ 2023-01-11 37/week @ 2023-01-18 52/week @ 2023-01-25

126 downloads per month
Used in 12 crates (9 directly)

Apache-2.0

89KB
999 lines

safina-executor

crates.io version license: Apache 2.0 unsafe forbidden pipeline status

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()
}).async_recv().await.unwrap()?;

Alternatives

Changelog

  • v0.3.3 - Eliminate spurious "resumed after completion" worker thread panics.
  • v0.3.2 - Re-export safina_sync::Receiver and safina_threadpool::NewThreadPoolError.
  • v0.3.1 - Use safina-async v0.2.1.
  • v0.3.0 - schedule_blocking to return new safina_sync::Receiver.
  • v0.2.1 - Update docs.
  • v0.2.0
    • Executor::new and Executor::with_name to return Result.
    • Upgrade to safina-threadpool v0.2.0.
  • v0.1.7 - block_on functions to take futures that are not Send.
  • v0.1.6 - Fix deadlock in block_on and block_on_unpin when task is awakened a second time.
  • v0.1.5 - Support stable Rust! Needs 1.51+.
  • v0.1.4 - Add schedule_blocking and Executor::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 and block_on without using Box::pin. Add spawn_unpin and block_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

Release Process

  1. Edit Cargo.toml and bump version number.
  2. Run ./release.sh

License: Apache-2.0

Dependencies