[][src]Crate safina_executor

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

This is a safe Rust async executor.

It is part of safina, a safe async runtime.

Features

  • forbid(unsafe_code)
  • Depends only on std
  • Good test coverage (100%)

Limitations

Documentation

https://docs.rs/safina-executor

Examples

safina_executor::increase_threads_to(1);
let (sender, receiver) = std::sync::mpsc::channel();
safina_executor::spawn(async move {
    sender.send(()).unwrap();
});
receiver.recv().unwrap();
std::thread::spawn(safina_executor::work);
let result = safina_executor::block_on(async {
    prepare_request().await?;
    execute_request().await
})?;

Alternatives

  • smol
    • popular
    • Contains generous amounts of unsafe code
  • async-std
    • popular
    • Contains generous amounts of unsafe code
  • tokio
    • very popular
    • Fast, internally complicated, and full of unsafe
  • nostd_async

Changelog

  • 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

  • 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, and increase_threads_to.
  • DONE - Add tests
  • DONE - Add docs
  • DONE - Publish on crates.io
  • DONE - Add an #[async_test] macro
  • Add a stress test
  • Add a benchmark
  • Make a version of the crate that uses unsafe once_cell and unsafe RawWaker and builds with Rust stable.
  • Add an #[async_main] macro

Release Process

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

Structs

ThreadStopTimeout

Returned by stop_threads when one or more worker threads fail to exit. This can happen when a task takes too long between awaits.

Functions

allow_threads

Clears the signal for worker threads to stop. Call this after stop_threads and before increase_threads_to or work.

block_on

Executes the future on the current thread and returns its result. Panics if the future panics.

block_on_unpin

Executes the future on the current thread and returns its result. Panics if the future panics.

increase_threads_to

Spawns new worker threads until the total number of workers is n.

num_threads_running

The number of worker threads currently running.

spawn

Adds a task that will execute fut. The task runs on any available worker thread.

spawn_unpin

Adds a task that will execute fut. The task runs on any available worker thread.

stop_threads

Signals all threads to stop. Waits for them all to stop.

work

Use the current thread as a worker in the runtime.