may icon indicating copy to clipboard operation
may copied to clipboard

macro select! : Polling a channel that already contained data may not trigger recv

Open ctemple opened this issue 1 year ago • 0 comments

The code is as follows

#[test]
    fn test_may_select() {
        may::config().set_workers(4usize);

        go! ( || {
            let (sx1, rx1) = may::sync::mpsc::channel();
            let (sx2, rx2) = may::sync::mpsc::channel();
            sx1.send(100i32);
            sx2.send(200i32);

            loop {
                may::select!(
                    v1 = rx1.recv() => {
                        println!("v1={:?}", v1);
                    },
                    v2 = rx2.recv() => {
                        println!("v2={:?}", v2);
                    }
                );
            }
        });
        std::thread::sleep(Duration::from_secs(2u64));
    }

Sometimes it can work normally

running 1 test
v1=Ok(100)
v2=Ok(200)
test service::tests::test_may_select ... ok

But sometimes

running 1 test
v1=Ok(100)
test service::tests::test_may_select ... ok

env rust = 1.68.2 stable-x86_64-pc-windows-msvc may = "0.3.42"

ctemple avatar Apr 18 '23 03:04 ctemple