11 releases
| 0.2.5 | Oct 27, 2024 |
|---|---|
| 0.2.4 | Mar 31, 2022 |
| 0.1.6 | Feb 25, 2022 |
| 0.1.5 | Mar 26, 2021 |
| 0.1.3 | Dec 29, 2020 |
#1681 in Asynchronous
49 downloads per month
Used in 11 crates
(3 directly)
34KB
423 lines
ARCHIVED ARCHIVED ARCHIVED
This crate is archived and will not be updated.
The code is now at
safina::sync in the
safina crate.
safina-sync
Structs for sharing or sending data between async tasks.
It is part of safina, a safe async runtime.
Features
Mutexwith an async lock methodoneshotandsync_channelwith async and blocking methodsforbid(unsafe_code)- Depends only on
std - 100% test coverage
- Works with
safina-executoror any async executor
Limitations
- Allocates
- No const constructor.
Uses
std::sync::Mutexinternally, which does not have a const constructor. See rust#66806 and const-eval#3. You can work around this with unstablecore::lazy::OnceCellor variousunsafecrates:lazy_static,once_cell,lazycell, andconquer-once.
Documentation
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
- async-lock
- Contains a little
unsafecode
- Contains a little
- futures-locks
- Contains a little
unsafecode
- Contains a little
- futures-util
- Very popular
- Full of
unsafe
- tokio-sync
- Very popular
- Fast
- Internally incredibly complicated
- Full of
unsafe
Changelog
- v0.2.4
- Implement
EqandPartialEqforReceiver,OneSender, andSyncSender. - Fix bug where
awaitonReceiverwould not wake senders.
- Implement
- v0.2.3 Fix race condition.
- v0.2.2 Fix deadlock on Linux.
- v0.2.1
- Add
sync_channelandSyncSender. - Add
Receiver::async_recvto let users await without writing ugly(&mut receiver).await. - Remove
Receiver::blockingand addtry_recv,recv, etc.
- Add
- v0.2.0 - Replace
Promisewithoneshot,OneSender, andReceiverthat supports async and blocking reads. - v0.1.6 - Update docs.
- v0.1.5 - Update docs
- v0.1.4 - Update docs, make
MutexGuard::newnon-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
- Edit
Cargo.tomland bump version number. - Run
./release.sh