use std::{
sync::Arc,
thread,
time::{Duration, SystemTime},
};
use crossbeam_utils::atomic::AtomicCell;
use nblock::{idle::NoOp, selector::DedicatedThreadSelector, task::Nonblock, Runtime};
#[test]
fn test_join_handle_try_take() {
let runtime = create_runtime();
let task = move || Nonblock::Complete("success".to_owned());
let handle = runtime.spawn("mytask", task);
let output = unwrap_timeout(move || handle.try_take().unwrap());
assert_eq!("success", output.as_str());
}
#[test]
fn test_join_handle_join() {
let runtime = create_runtime();
let task = move || Nonblock::Complete("success".to_owned());
let handle = runtime.spawn("mytask", task);
let output = handle.join(NoOp).unwrap();
assert_eq!("success", output.as_str());
}
#[test]
fn test_join_handle_on_complete_from_task_thread() {
let runtime = create_runtime();
// create task that will be sleeping while on_complete_hook is set
let task = move || {
thread::sleep(Duration::from_millis(100));
Nonblock::Complete("success".to_owned())
};
let output = Arc::new(AtomicCell::