summaryrefslogtreecommitdiffstats
path: root/tests-integration/tests/macros_select.rs
blob: 4c4fef7ce77a8f86d63d09c328ef7b4c415e4188 (plain)
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
#![cfg(feature = "macros")]

use futures::channel::oneshot;
use futures::executor::block_on;
use std::thread;

#[test]
fn join_with_select() {
    block_on(async {
        let (tx1, mut rx1) = oneshot::channel::<i32>();
        let (tx2, mut rx2) = oneshot::channel::<i32>();

        thread::spawn(move || {
            tx1.send(123).unwrap();
            tx2.send(456).unwrap();
        });

        let mut a = None;
        let mut b = None;

        while a.is_none() || b.is_none() {
            tokio::select! {
                v1 = (&mut rx1), if a.is_none() => a = Some(v1.unwrap()),
                v2 = (&mut rx2), if b.is_none() => b = Some(v2.unwrap()),
            }
        }

        let (a, b) = (a.unwrap(), b.unwrap());

        assert_eq!(a, 123);
        assert_eq!(b, 456);
    });
}