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