#async-task #async #safe #async-executor #async-test #future #select

safina-sync

Safe structs for sharing or sending data between async tasks

10 releases

0.2.4 Mar 31, 2022
0.2.3 Mar 17, 2022
0.1.6 Feb 25, 2022
0.1.5 Mar 26, 2021
0.1.3 Dec 29, 2020

#869 in Asynchronous

Download history 42/week @ 2024-01-12 20/week @ 2024-01-19 12/week @ 2024-01-26 10/week @ 2024-02-02 29/week @ 2024-02-09 36/week @ 2024-02-16 39/week @ 2024-02-23 45/week @ 2024-03-01 53/week @ 2024-03-08 41/week @ 2024-03-15 55/week @ 2024-03-22 70/week @ 2024-03-29 36/week @ 2024-04-05 43/week @ 2024-04-12 45/week @ 2024-04-19 41/week @ 2024-04-26

177 downloads per month
Used in 14 crates (5 directly)

Apache-2.0

34KB
423 lines

safina-sync

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

Structs for sharing or sending data between async tasks.

It is part of safina, a safe async runtime.

Features

  • Mutex with an async lock method
  • oneshot and sync_channel with async and blocking methods
  • forbid(unsafe_code)
  • Depends only on std
  • 100% test coverage
  • Works with safina-executor or any async executor

Limitations

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.2.4
    • Implement Eq and PartialEq for Receiver, OneSender, and SyncSender.
    • Fix bug where await on Receiver would not wake senders.
  • v0.2.3 Fix race condition.
  • v0.2.2 Fix deadlock on Linux.
  • v0.2.1
    • Add sync_channel and SyncSender.
    • Add Receiver::async_recv to let users await without writing ugly (&mut receiver).await.
    • Remove Receiver::blocking and add try_recv, recv, etc.
  • v0.2.0 - Replace Promise with oneshot, OneSender, and Receiver that supports async and blocking reads.
  • v0.1.6 - Update docs.
  • v0.1.5 - Update docs
  • v0.1.4 - Update docs, make MutexGuard::new non-public
  • 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

  • Add Barrier
  • Add RwLock
  • Add WaitableBool
  • 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