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
|
use std::future::Future;
use atomic_refcell::AtomicRefCell;
fn spawn<Fut>(_future: Fut)
where
Fut: Future<Output = ()> + Send + Sync,
{
}
async fn something_async() {}
// see https://github.com/bholley/atomic_refcell/issues/24
#[test]
fn test_atomic_ref_in_spawn() {
let arc: Box<dyn Fn() -> usize + Send + Sync> = Box::new(|| 42);
let a = AtomicRefCell::new(arc);
spawn(async move {
let x = a.borrow();
something_async().await;
assert_eq!(x(), 42);
});
}
#[test]
fn test_atomic_ref_mut_in_spawn() {
let arc: Box<dyn Fn() -> usize + Send + Sync> = Box::new(|| 42);
let a = AtomicRefCell::new(arc);
spawn(async move {
let x = a.borrow_mut();
something_async().await;
assert_eq!(x(), 42);
});
}
|