#safe #async #select #future

safina-sync

Safe async select function, for awaiting multiple futures

4 releases

0.1.3 Dec 29, 2020
0.1.2 Dec 29, 2020
0.1.1 Dec 24, 2020
0.1.0 Dec 13, 2020

#364 in Asynchronous


Used in 8 crates (3 directly)

Apache-2.0

21KB
358 lines

safina-sync

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

This is a safe Rust library for sharing or sending data between async tasks.

It is part of safina, a safe async runtime.

Features

  • forbid(unsafe_code)
  • Depends only on std
  • Good test coverage (100%)
  • Works with safina-executor or any async executor

Limitations

  • Allocates

Documentation

https://docs.rs/safina-sync

Examples

use std::sync::Arc;
use safina_async_test::async_test;
use safina_sync::Mutex;
let shared_counter: Arc<Mutex<u32>> = get_shared_data();
{
    let mut counter_guard = shared_counter.lock().await;
    *counter_guard += 1;
    // some_async_fn().await; // Cannot await while holding a MutexGuard.
}
some_async_fn().await; // Await is ok after releasing MutexGuard.

Alternatives

Changelog

  • v0.1.3 - Fix Promise type parameter
  • v0.1.2 - Add Promise
  • v0.1.1 - Improve Mutex performance when there are many waiters
  • v0.1.0 - First published version

TO DO

  • DONE - Implement Mutex with tests & docs
  • DONE - Publish on crates.io
  • DONE - Add Promise
  • Add Barrier
  • Add RwLock
  • Add WaitableBool
  • Add Channel (single receiver)
  • Add UnboundedChannel
  • Add WaitableQueue (multiple receivers)
  • Add UnboundedWaitableQueue
  • Add Topic (copies message to every receiver)

Release Process

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

License: Apache-2.0

No runtime deps