threadfin/lib.rs
1//! A thread pool for running multiple tasks on a configurable group of threads.
2//!
3//! Extra features:
4//!
5//! - Dynamic pool size based on load
6//! - Support for async tasks
7//! - Tasks return a handle which can be joined or awaited for the return value
8//! - Optional common process-wide thread pool
9//!
10//! ## Async support
11//!
12//! Threadfin supports asynchronous usage via futures, and allows you to mix and
13//! match both synchronous and asynchronous tasks within a single thread pool.
14//!
15//! ## Examples
16//!
17//! ```
18//! // Create a new pool.
19//! let pool = threadfin::builder().size(8).build();
20//!
21//! // Schedule some work.
22//! let compute_task = pool.execute(|| {
23//! // Some expensive computation
24//! 2 + 2
25//! });
26//!
27//! // Do something in the meantime.
28//! println!("Waiting for result...");
29//!
30//! // Wait for the task to complete and get the result.
31//! let sum = compute_task.join();
32//! println!("Sum: 2 + 2 = {}", sum);
33//! ```
34
35mod common;
36mod error;
37mod pool;
38mod task;
39mod wakers;
40mod worker;
41
42pub use crate::{
43 common::*,
44 error::*,
45 pool::{Builder, PerCore, SizeConstraint, ThreadPool},
46 task::Task,
47};
48
49/// Get a builder for creating a customized thread pool.
50///
51/// A shorthand for [`ThreadPool::builder`].
52#[inline]
53pub fn builder() -> Builder {
54 ThreadPool::builder()
55}