fn multishot_change_waker<F>(f: F, expect: Result<i32, RecvError>)
    where
        F: FnOnce(Sender<i32>) + Send + Copy + 'static,
    {
        let test_waker1 = Arc::new(TestWaker::new());
        let waker1 = test_waker1.clone().into();
        let mut cx1 = Context::from_waker(&waker1);
        let test_waker2 = Arc::new(TestWaker::new());
        let waker2 = test_waker2.clone().into();
        let mut cx2 = Context::from_waker(&waker2);
        let test_waker3 = Arc::new(TestWaker::new());
        let waker3 = test_waker3.clone().into();
        let mut cx3 = Context::from_waker(&waker3);

        // Change waker and consume sender.
        {
            let (sender, mut receiver) = channel::<i32>();
            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);

            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(res, Poll::Pending);
            spawn_and_join(move || f(sender));
            assert_eq!(test_waker2.take_count(), 1);
            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(test_waker1.take_count(), 0);
            assert_eq!(test_waker2.take_count(), 0);
            assert_eq!(res, Poll::Ready(expect));
        }

        // Change waker twice and consume sender.
        {
            let (sender, mut receiver) = channel::<i32>();
            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);

            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx3);
            assert_eq!(res, Poll::Pending);
            spawn_and_join(move || f(sender));
            assert_eq!(test_waker3.take_count(), 1);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(test_waker1.take_count(), 0);
            assert_eq!(test_waker2.take_count(), 0);
            assert_eq!(res, Poll::Ready(expect));
        }
    }
// Changes the waker before executing a closure consuming the sender.
Changes the waker before executing a closure consuming the sender.
Changes the waker before executing a closure consuming the sender .
fn multishot_change_waker<F>(f: F, expect: Result<i32, RecvError>)
    where
        F: FnOnce(Sender<i32>) + Send + Copy + 'static,
    {
        let test_waker1 = Arc::new(TestWaker::new());
        let waker1 = test_waker1.clone().into();
        let mut cx1 = Context::from_waker(&waker1);
        let test_waker2 = Arc::new(TestWaker::new());
        let waker2 = test_waker2.clone().into();
        let mut cx2 = Context::from_waker(&waker2);
        let test_waker3 = Arc::new(TestWaker::new());
        let waker3 = test_waker3.clone().into();
        let mut cx3 = Context::from_waker(&waker3);
        // Change waker and consume sender.
        {
            let (sender, mut receiver) = channel::<i32>();
            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);
            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(res, Poll::Pending);
            spawn_and_join(move || f(sender));
            assert_eq!(test_waker2.take_count(), 1);
            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(test_waker1.take_count(), 0);
            assert_eq!(test_waker2.take_count(), 0);
            assert_eq!(res, Poll::Ready(expect));
        }
        // Change waker twice and consume sender.
        {
            let (sender, mut receiver) = channel::<i32>();
            let mut fut = receiver.recv();
            let mut fut = Pin::new(&mut fut);
            let res = fut.as_mut().poll(&mut cx1);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(res, Poll::Pending);
            let res = fut.as_mut().poll(&mut cx3);
            assert_eq!(res, Poll::Pending);
            spawn_and_join(move || f(sender));
            assert_eq!(test_waker3.take_count(), 1);
            let res = fut.as_mut().poll(&mut cx2);
            assert_eq!(test_waker1.take_count(), 0);
            assert_eq!(test_waker2.take_count(), 0);
            assert_eq!(res, Poll::Ready(expect));
        }
    }
fn multishot_change_waker < F > ( f : F , expect : Result < i32 , RecvError > ) where F : FnOnce ( Sender < i32 > ) + Send + Copy + ' static , { let test_waker1 = Arc :: new ( TestWaker :: new ( ) ) ; let waker1 = test_waker1 . clone ( ) . into ( ) ; let mut cx1 = Context :: from_waker ( & waker1 ) ; let test_waker2 = Arc :: new ( TestWaker :: new ( ) ) ; let waker2 = test_waker2 . clone ( ) . into ( ) ; let mut cx2 = Context :: from_waker ( & waker2 ) ; let test_waker3 = Arc :: new ( TestWaker :: new ( ) ) ; let waker3 = test_waker3 . clone ( ) . into ( ) ; let mut cx3 = Context :: from_waker ( & waker3 ) ; // Change waker and consume sender. { let ( sender , mut receiver ) = channel :: < i32 > ( ) ; let mut fut = receiver . recv ( ) ; let mut fut = Pin :: new ( & mut fut ) ; let res = fut . as_mut ( ) . poll ( & mut cx1 ) ; assert_eq ! ( res Poll Pending ) ; let res = fut . as_mut ( ) . poll ( & mut cx2 ) ; assert_eq ! ( res Poll Pending ) ; spawn_and_join ( move | | f ( sender ) ) ; assert_eq ! ( test_waker2 take_count ( ) 1 ) ; let res = fut . as_mut ( ) . poll ( & mut cx1 ) ; assert_eq ! ( test_waker1 take_count ( ) 0 ) ; assert_eq ! ( test_waker2 take_count ( ) 0 ) ; assert_eq ! ( res Poll Ready ( expect ) ) ; } // Change waker twice and consume sender. { let ( sender , mut receiver ) = channel :: < i32 > ( ) ; let mut fut = receiver . recv ( ) ; let mut fut = Pin :: new ( & mut fut ) ; let res = fut . as_mut ( ) . poll ( & mut cx1 ) ; assert_eq ! ( res Poll Pending ) ; let res = fut . as_mut ( ) . poll ( & mut cx2 ) ; assert_eq ! ( res Poll Pending ) ; let res = fut . as_mut ( ) . poll ( & mut cx3 ) ; assert_eq ! ( res Poll Pending ) ; spawn_and_join ( move | | f ( sender ) ) ; assert_eq ! ( test_waker3 take_count ( ) 1 ) ; let res = fut . as_mut ( ) . poll ( & mut cx2 ) ; assert_eq ! ( test_waker1 take_count ( ) 0 ) ; assert_eq ! ( test_waker2 take_count ( ) 0 ) ; assert_eq ! ( res Poll Ready ( expect ) ) ; } }
Changes the waker before executing a closure consuming the sender.
Changes the waker before executing a closure consuming the sender .
f
F
expect
Result<i32, RecvError>