Crates.io | safina-sync |
lib.rs | safina-sync |
version | 0.2.5 |
source | src |
created_at | 2020-12-13 22:48:13.121828 |
updated_at | 2024-10-27 23:38:07.95954 |
description | Safe structs for sharing or sending data between async tasks - ARCHIVED: Code moved to `safina` crate. |
homepage | |
repository | https://gitlab.com/leonhard-llc/safina-rs |
max_upload_size | |
id | 322545 |
size | 52,264 |
This crate is archived and will not be updated.
The code is now at
safina::sync
in the
safina
crate.
Structs for sharing or sending data between async tasks.
It is part of safina
, a safe async runtime.
Mutex
with an async lock methodoneshot
and sync_channel
with async and blocking methodsforbid(unsafe_code)
std
safina-executor
or any async executorstd::sync::Mutex
internally, which does not have a const constructor.
See rust#66806
and const-eval#3.
You can work around this with unstable
core::lazy::OnceCell
or various unsafe
crates:
lazy_static
,
once_cell
,
lazycell
, and
conquer-once
.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.
unsafe
codeunsafe
codeunsafe
unsafe
Eq
and PartialEq
for Receiver
, OneSender
, and SyncSender
.await
on Receiver
would not wake senders.sync_channel
and SyncSender
.Receiver::async_recv
to let users await without writing ugly (&mut receiver).await
.Receiver::blocking
and add try_recv
, recv
, etc.Promise
with oneshot
, OneSender
, and Receiver
that supports async and blocking reads.MutexGuard::new
non-publicBarrier
RwLock
WaitableBool
UnboundedChannel
WaitableQueue
(multiple receivers)UnboundedWaitableQueue
Topic
(copies message to every receiver)Cargo.toml
and bump version number../release.sh