use std::{thread, time};
use swctx::mkpair;
#[test]
fn say_hello_before_wait() {
let (sctx, wctx) = mkpair::<&str, (), &str>();
let jh = thread::spawn(move || {
sctx.set("hello").unwrap();
});
jh.join().unwrap();
assert_eq!(wctx.wait().unwrap(), "hello");
}
#[test]
fn say_hello_after_wait() {
let (sctx, wctx) = mkpair::<&str, (), &str>();
let jh = thread::spawn(move || {
thread::sleep(time::Duration::from_millis(500));
sctx.set("hello").unwrap();
});
assert_eq!(wctx.wait().unwrap(), "hello");
jh.join().unwrap();
}
#[test]
fn async_say_hello_before_wait() {
let tokrt = tokio::runtime::Runtime::new().unwrap();
let (sctx, wctx) = mkpair::<&str, (), &str>();
let jh = thread::spawn(move || {
sctx.set("hello").unwrap();
});
jh.join().unwrap();
tokrt.block_on(async {
assert_eq!(wctx.wait_async().await.unwrap(), "hello");
});
}
#[test]
fn async_say_hello_after_wait() {
let tokrt = tokio::runtime::Runtime::new().unwrap();
let (sctx, wctx) = mkpair::<&str, (), &str>();
let jh = thread::spawn(move || {
thread::sleep(time::Duration::from_millis(500));
sctx.set("hello").unwrap();
});
tokrt.block_on(async {
assert_eq!(wctx.wait_async().await.unwrap(), "hello");
});
jh.join().unwrap();
}