File: async.rs

package info (click to toggle)
rust-atomic-refcell 0.1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 140 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 782 bytes parent folder | download
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);
    });
}