permit
permit::Permit
is a struct for cancelling operations.
Use Cases
- Graceful server shutdown
- Cancel operations that take too long
- Stop in-flight operations when revoking authorization
Features
- Subordinate permits. Revoking a permit also revokes its subordinates, recursively.
- Drop a permit to revoke its subordinates, recursively.
- Wait for all subordinate permits to drop.
- Similar to Golang's
context
- Depends only on
std
. forbid(unsafe_code)
- 100% test coverage
Limitations
- Does not hold data values
- Allocates. Uses
alloc::sync::Arc
.
Alternatives
async_ctx
- Good API
- Async only
io-context
- Holds Any values
- Unmaintained
ctx
Related Crates
Example
Graceful shutdown:
let top_permit = new;
// Start some worker threads.
for _ in 0..5
wait_for_shutdown_signal;
// Revoke all thread permits and wait for them to
// finish an drop their permits.
top_permit.revoke.try_wait_for;
Cargo Geiger Safety Report
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(unsafe_code)]
❓ = No `unsafe` usage found, missing #![forbid(unsafe_code)]
☢️ = `unsafe` usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 permit 0.1.1
0/0 0/0 0/0 0/0 0/0
Changelog
- v0.1.1 - Make
revoke
return&Self
- v0.1.0 - Initial version
Happy Contributors 🙂
Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:
- Always respond within 24 hours
- Provide clear & concrete feedback
- Immediately make a new release for your accepted change
License: Apache-2.0