2 unstable releases
0.2.0 | Nov 26, 2024 |
---|---|
0.1.0 | Feb 3, 2023 |
#422 in Asynchronous
176 downloads per month
12KB
167 lines
procsem
The ProcSem is a semaphore used to lock a sequence of operations that may span multiple threads/tasks.
lib.rs
:
A simple process semaphore.
(Note: The word process should be read as a sequence of operations, rather than an operating system process).
The ProcSem
is intended to allow mutual exclusion of a chain of
operations that may span over several threads/tasks.
This is much like a Mutex
, but it differs in that it holds no generic
parameter and the ProcCtx
(the equivalent of Mutex
's MutexGuard
) is
Send
, because it is explicitly meant to be passed around between
threads/tasks. It supports blocking, nonblocking and async lock
acquisition.
Progress reporting
When a ProcSem
is created, it can optionally be handed an object that
implements StateReporter
. If a ProcSem
has a StateReporter
associated with it, then an acquired ProcCtx
can use
[ProcCtx::action()
], [ProcCtx::progress()
] to pass progress information
to the StateReporter
implementor.
Once a ProcCtx
is about to terminate, [ProcCtx::end()
] can be used to
signal a final message that can be retrieved by the ProcSem
object.
Dependencies
~1–5.5MB
~25K SLoC