Structs for sharing or sending data between async tasks.
It is part of safina
, a safe async runtime.
safina_sync::Mutex
has an async lock methodsafina_sync::Promise
is a one-shot channel which you can awaitforbid(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
.rust
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
Promise
with oneshot
, OneSender
, and Receiver
that supports async and blocking reads.MutexGuard::new
non-publicBarrier
RwLock
WaitableBool
Channel
(single receiver)UnboundedChannel
WaitableQueue
(multiple receivers)UnboundedWaitableQueue
Topic
(copies message to every receiver)Cargo.toml
and bump version number../release.sh
License: Apache-2.0