[][src]Crate safina

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

A safe Rust async runtime.

Features

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

Limitations

Documentation

https://docs.rs/safina

safina_async_test has an #[async_test] macro for running async fn test functions.

Examples

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

Alternatives

  • smol
    • Popular
    • Contains generous amounts of unsafe code
  • async-std
    • Very popular
    • Contains generous amounts of unsafe code
  • futures
    • Very popular
    • Contains generous amounts of unsafe code
  • tokio
    • Very popular
    • Fast
    • Internally extremely complicated
    • Full of unsafe
  • bastion
    • Generous amounts of unsafe code
  • nostd_async

Changelog

  • v0.1.5 - Add safina_sync::Mutex
  • v0.1.4 - Upgrade to new safina-executor version which removes need for Box::pin.
  • v0.1.3 - Update docs
  • v0.1.2 - Renamed safina crate to safina-executor. Added new safina crate with re-exports, examples, and integration tests.
  • v0.1.1 - Add badges to readme
  • v0.1.0 - First published version

TO DO

  • Add an integration test
  • Add init function that starts worker threads and the timer thread.
  • Make it work on Rust stable
  • Add an #[async_main] macro

Release Process

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

Structs

DeadlineExceeded
Mutex

A wrapper around std::sync::Mutex with an async lock method.

MutexGuard

An RAII scoped lock of a Mutex. It automatically unlocks the mutex when dropped (falls out of scope).

Enums

OptionAB
OptionABC
OptionABCD
OptionABCDE

Functions

block_on

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.

select_ab

Awaits both futures and returns the value from the one that completes first.

select_abc

Awaits the futures and returns the value from the one that completes first.

select_abcd

Awaits the futures and returns the value from the one that completes first.

select_abcde

Awaits the futures and returns the value from the one that completes first.

sleep_for

Returns duration time from now.

sleep_until

Returns after deadline.

spawn

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

start_timer_thread

Starts the worker thread, if it's not already started. You must call this before calling sleep_until or sleep_for.

with_deadline

Awaits inner, but returns DeadlineExceeded after deadline.

with_timeout

Awaits inner, but returns DeadlineExceeded after duration time from now.

work

Use the current thread as a worker in the runtime.