async_cell/
cons.rs

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
//! A waker cons cell.

use alloc::sync::Arc;
use alloc::task::Wake;
use core::task::Waker;

pub struct Cons(pub Waker, pub Waker);

impl Wake for Cons {
    fn wake(self: Arc<Self>) {
        match Arc::try_unwrap(self) {
            Ok(Cons(a, b)) => {
                a.wake();
                b.wake();
            }
            Err(arc) => Cons::wake_by_ref(&arc),
        }
    }

    fn wake_by_ref(self: &Arc<Self>) {
        self.0.wake_by_ref();
        self.1.wake_by_ref();
    }
}

pub fn wake_both(a: Waker, b: Waker) -> Waker {
    Arc::new(Cons(a, b)).into()
}