mod cross_thread_pool;
mod pool;
mod tasks;
mod thread_local_pool;
mod worker;
pub use cross_thread_pool::CrossThreadPool;
pub use pool::ThreadPool;
pub use thread_local_pool::ThreadLocalPool;
pub use worker::Worker;
#[cfg(test)]
mod tests {
use super::ThreadPool;
use crate::errors::new_error;
use crate::scheduler::Scheduler;
use crate::start_detached::StartDetached;
use crate::then::Then;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
const SLEEP_DELAY: Duration = Duration::from_millis(50);
#[test]
fn it_correctly_handles_multiple_wakeups() {
let pool = ThreadPool::new(1).unwrap();
let (tx, rx) = mpsc::channel();
{
let tx = tx.clone();
(pool.schedule_value((String::from("warmup"),))
| Then::from(move |(s,): (String,)| tx.send(s).map_err(new_error)))
.start_detached();
}
assert_eq!(String::from("warmup"), rx.recv().unwrap());
thread::sleep(SLEEP_DELAY);
{
let tx = tx.clone();
(pool.schedule_value((String::from("first"),))
| Then::from(move |(s,): (String,)| tx.send(s).map_err(new_error)))
.start_detached();
}
assert_eq!(String::from("first"), rx.recv().unwrap());
thread::sleep(SLEEP_DELAY);
{
let tx = tx.clone();
(pool.schedule_value((String::from("second"),))
| Then::from(move |(s,): (String,)| tx.send(s).map_err(new_error)))
.start_detached();
}
assert_eq!(String::from("second"), rx.recv().unwrap());
drop(pool);
}
}