fn multishot_loom_notify<F>(f: F, expect: Result<i32, RecvError>)
    where
        F: FnOnce(Sender<i32>) + Send + Sync + Copy + 'static,
    {
        loom::model(move || {
            let test_waker = Arc::new(TestWaker::new());
            let waker = test_waker.clone().into();
            let mut cx = Context::from_waker(&waker);

            let (sender, mut receiver) = channel();

            let has_message = Arc::new(AtomicBool::new(false));
            thread::spawn({
                let has_message = has_message.clone();
                move || {
                    f(sender);
                    has_message.store(true, Ordering::Release);
                }
            });

            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);

            let res = fut.as_mut().poll(&mut cx);

            match res {
                Poll::Pending => {
                    let msg = has_message.load(Ordering::Acquire);
                    let event_count = test_waker.take_count();
                    if event_count == 0 {
                        // Make sure that if the waker was not notified, then no
                        // message was sent (or equivalently, if a message was sent,
                        // the waker was notified).
                        assert_eq!(msg, false);
                    } else {
                        assert_eq!(event_count, 1);
                        // Make sure that if the waker was notified, the message
                        // can be retrieved (this is crucial to ensure that
                        // notifications are not lost).
                        let res = fut.as_mut().poll(&mut cx);
                        assert_eq!(test_waker.take_count(), 0);
                        assert_eq!(res, Poll::Ready(expect));
                    }
                }
                Poll::Ready(val) => {
                    assert_eq!(val, expect);
                }
            }
        });
    }
// Executes a closure consuming the sender and checks the result of the
// completed future.
Executes a closure consuming the sender and checks the result of the
completed future.
Executes a closure consuming the sender and checks the result of the completed future .
fn multishot_loom_notify<F>(f: F, expect: Result<i32, RecvError>)
    where
        F: FnOnce(Sender<i32>) + Send + Sync + Copy + 'static,
    {
        loom::model(move || {
            let test_waker = Arc::new(TestWaker::new());
            let waker = test_waker.clone().into();
            let mut cx = Context::from_waker(&waker);
            let (sender, mut receiver) = channel();
            let has_message = Arc::new(AtomicBool::new(false));
            thread::spawn({
                let has_message = has_message.clone();
                move || {
                    f(sender);
                    has_message.store(true, Ordering::Release);
                }
            });
            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);
            let res = fut.as_mut().poll(&mut cx);
            match res {
                Poll::Pending => {
                    let msg = has_message.load(Ordering::Acquire);
                    let event_count = test_waker.take_count();
                    if event_count == 0 {
                        // Make sure that if the waker was not notified, then no
                        // message was sent (or equivalently, if a message was sent,
                        // the waker was notified).
                        assert_eq!(msg, false);
                    } else {
                        assert_eq!(event_count, 1);
                        // Make sure that if the waker was notified, the message
                        // can be retrieved (this is crucial to ensure that
                        // notifications are not lost).
                        let res = fut.as_mut().poll(&mut cx);
                        assert_eq!(test_waker.take_count(), 0);
                        assert_eq!(res, Poll::Ready(expect));
                    }
                }
                Poll::Ready(val) => {
                    assert_eq!(val, expect);
                }
            }
        });
    }
fn multishot_loom_notify < F > ( f : F , expect : Result < i32 , RecvError > ) where F : FnOnce ( Sender < i32 > ) + Send + Sync + Copy + ' static , { loom :: model ( move | | { let test_waker = Arc :: new ( TestWaker :: new ( ) ) ; let waker = test_waker . clone ( ) . into ( ) ; let mut cx = Context :: from_waker ( & waker ) ; let ( sender , mut receiver ) = channel ( ) ; let has_message = Arc :: new ( AtomicBool :: new ( false ) ) ; thread :: spawn ( { let has_message = has_message . clone ( ) ; move | | { f ( sender ) ; has_message . store ( true , Ordering :: Release ) ; } } ) ; let mut fut = receiver . recv ( ) ; let mut fut = Pin :: new ( & mut fut ) ; let res = fut . as_mut ( ) . poll ( & mut cx ) ; match res { Poll :: Pending => { let msg = has_message . load ( Ordering :: Acquire ) ; let event_count = test_waker . take_count ( ) ; if event_count == 0 { // Make sure that if the waker was not notified, then no // message was sent (or equivalently, if a message was sent, // the waker was notified). assert_eq ! ( msg false ) ; } else { assert_eq ! ( event_count 1 ) ; // Make sure that if the waker was notified, the message // can be retrieved (this is crucial to ensure that // notifications are not lost). let res = fut . as_mut ( ) . poll ( & mut cx ) ; assert_eq ! ( test_waker take_count ( ) 0 ) ; assert_eq ! ( res Poll Ready ( expect ) ) ; } } Poll :: Ready ( val ) => { assert_eq ! ( val expect ) ; } } } ) ; }
Executes a closure consuming the sender and checks the result of the
completed future.
Executes a closure consuming the sender and checks the result of the completed future .
f
F
expect
Result<i32, RecvError>