| Crates.io | future-pool |
| lib.rs | future-pool |
| version | 0.1.0 |
| created_at | 2025-10-17 09:47:27.301581+00 |
| updated_at | 2025-10-17 09:47:27.301581+00 |
| description | A simple yet efficient worker pool implementation for async task processing |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1887438 |
| size | 50,922 |
Simple async worker pool built on Rust std::thread and futures.
Avoids per-task tokio::spawn overhead with a clear task + context API.
process futures on worker threads via block_on.WorkerTask with a per-task struct and a shared Context.Add this to your Cargo.toml:
[dependencies]
future-pool = "0.1.0"
WorkerTask:struct MyTask { /* per-task fields */ }
impl WorkerTask for MyTask {
type Context = /* shared state the task needs */;
async fn process(self, ctx: &Self::Context) { /* use ctx */ }
}
Context and configuration:let context = /* build context */;
let config = WorkerPoolConfig { /* worker count, buffer size, affinity */ };
let mut pool = WorkerPool::new(context, config);
spawn:pool.spawn(MyTask { /* data */ }).await?;
See examples/ for a complete program.
trait WorkerTask
type Context: Clone + Send + Sync + 'staticfn process(self, &Context) -> impl Future<Output=()> + Sendstruct WorkerPool<T: WorkerTask>
fn new(context: T::Context, config: WorkerPoolConfig) -> Selfasync fn spawn(&mut self, task: T) -> Result<(), SendError<T>>fn worker_count(&self) -> usizefn shutdown(self)WorkerPoolConfig options:
num_workers: Number of worker threads (defaults to available CPUs)buffer_size: Channel buffer size per workerenable_core_affinity: Opt-in CPU core pinningcore_offset: Starting core offset for pinning (auto-calculated if not set)Defaults: num_workers=None, buffer_size=DEFAULT_CHANNEL_SIZE, enable_core_affinity=false, core_offset=None.
tokio::spawn overhead matters