taskq
A small, thread-safe, in-memory task queue for synchronous producers and async or synchronous consumers.
Features
- thread-safe submission and consumption
- async task consumption without blocking runtime workers
- synchronous non-blocking task polling
- queue-local, internally generated
i64task IDs - optional idempotency with generic task keys
- task lifecycle status and timestamps
- bounded capacity with explicit
QueueFullsignaling - generic payload types
- finished task cleanup after a configurable TTL
- running task timeout detection
- single-process, multi-threaded operation
- metrics and tracing
- task priorities
- task cancellation
- persistent or distributed backends
Installation
Usage
use ;
async
Use try_pop_task when a synchronous consumer must poll without waiting.
Received tasks can be consumed with into_payload or into_parts when the
consumer needs ownership of the payload.
Queue semantics
- The queue is bounded.
submit_taskandsubmit_task_with_keynever wait for capacity; they returnTaskError::QueueFullso callers can retry, back off, or reject work according to their own policy. - Task IDs are unique only within one queue instance. They are not durable or globally unique identifiers.
- A task key remains reserved until its terminal status is removed after the configured finished-task TTL.
pop_taskwaits asynchronously, whiletry_pop_taskreturns immediately.- Tasks and statuses live only in memory and are lost when the process exits.
- Every queue instance owns one background maintenance thread for status cleanup and running-task timeout detection.
Benchmark
The benchmark retries submissions that receive QueueFull, so producer-heavy
configurations measure bounded-queue contention instead of terminating early.
License
Licensed under either of the Apache License, Version 2.0 or the MIT license, at your option.