Expand description
§workit
workit
is a simple way to queue a task in a Rust project to be executed
later. It is designed for projects that do not want to implement an async
runtime like tokio, and may find a home in projects handling streams of data
that may exhibit burst behavior.
The fundamental interface targets single-threaded projects: you queue up
closures that workit can take ownership of (in practice, you often use
Arc<Mutex
Specifically, passed functions must be FnMut() + Send and return solely a boolean indicating whether the task succeeded or failed.
You can customize how many times (at most) a task should be attempted, and how long to wait in between reattempts of the same task if it fails.
workit is fully thread-safe, operates with a single global queue in the background, and can actually be used in any context (but if you intend to spawn multiple threads to process work and are willing to use an async runtime, you should probably use a modern work-stealing queueing library etc. instead).
Enums§
- Queue
Status - Denotes the state of the global workit task queue.
Functions§
- do_work
- Executes work and returns when:
- enqueue
- Adds task to the queue, with maximum attempts and cooldown between attempts if the task fails as added parameters. Does not execute the work.
- reset_
queue - Clears out the entire queue without doing the work. Keeps a lock on the queue continuously until it is empty.