permit::Permit
is a struct for cancelling operations.
Future
. You can await
a permit and return when it is revoked.context
std
.forbid(unsafe_code)
alloc::sync::Arc
.async_ctx
stopper
io-context
ctx
Graceful shutdown:
rust
let top_permit = permit::Permit::new();
// Start some worker threads.
for _ in 0..5 {
let permit = top_permit.new_sub();
std::thread::spawn(move || {
while !permit.is_revoked() {
// ...
}
});
}
wait_for_shutdown_signal();
// Revoke all thread permits and wait for them to
// finish and drop their permits.
top_permit
.revoke()
.wait_subs_timeout(Duration::from_secs(3))
.unwrap();
```
Metric output format: x/y x = unsafe code used by the build y = total unsafe code found in the crate
Symbols:
🔒 = No unsafe
usage found, declares #![forbid(unsafecode)]
❓ = No unsafe
usage found, missing #![forbid(unsafecode)]
☢️ = unsafe
usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 permit 0.2.1
0/0 0/0 0/0 0/0 0/0
```
sleep
and sleep_until
would sometimes not return early.try_wait_for
to wait_subs_timeout
try_wait_until
to wait_subs_deadline
wait*
methodswait
sleep
and sleep_until
Debug
revoke()
and then wait()
would not wait.std::task::Waker
structs.Future
revoke
return &Self
License: Apache-2.0