Repository: rust-lang-nursery/futures-rs
Pull request #1908 (2019-10-09 20:54:45)

Rename oneshot:Sender::poll_cancel to poll_canceled
In most other places, `poll_action` means that 'action' is happening
asynchronously. The name `poll_cancel` implies that the call will cancel
the oneshot, but really we just wish to poll if it *has been* canceled.

cramertj: Makes sense to me, thanks!

Patch:
diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs
index 5c9b3fbb..ed552509 100644
--- a/futures-channel/src/oneshot.rs
+++ b/futures-channel/src/oneshot.rs
@@ -43,7 +43,7 @@ struct Inner<T> {
     /// unlocked and ready to be inspected.
     ///
     /// For `Sender` if this is `true` then the oneshot has gone away and it
-    /// can return ready from `poll_cancel`.
+    /// can return ready from `poll_canceled`.
     complete: AtomicBool,
 
     /// The actual data being transferred as part of this `Receiver`. This is
@@ -64,7 +64,7 @@ struct Inner<T> {
     rx_task: Lock<Option<Waker>>,
 
     /// Like `rx_task` above, except for the task blocked in
-    /// `Sender::poll_cancel`. Additionally, `Lock` cannot be `UnsafeCell`.
+    /// `Sender::poll_canceled`. Additionally, `Lock` cannot be `UnsafeCell`.
     tx_task: Lock<Option<Waker>>,
 }
 
@@ -153,7 +153,7 @@ impl<T> Inner<T> {
         }
     }
 
-    fn poll_cancel(&self, cx: &mut Context<'_>) -> Poll<()> {
+    fn poll_canceled(&self, cx: &mut Context<'_>) -> Poll<()> {
         // Fast path up first, just read the flag and see if our other half is
         // gone. This flag is set both in our destructor and the oneshot
         // destructor, but our destructor hasn't run yet so if it's set then the
@@ -298,7 +298,7 @@ impl<T> Inner<T> {
 
     fn drop_rx(&self) {
         // Indicate to the `Sender` that we're done, so any future calls to
-        // `poll_cancel` are weeded out.
+        // `poll_canceled` are weeded out.
         self.complete.store(true, SeqCst);
 
         // If we've blocked a task then there's no need for it to stick around,
@@ -354,14 +354,14 @@ impl<T> Sender<T> {
     /// alive and may be able to receive a message if sent. The current task,
     /// however, is scheduled to receive a notification if the corresponding
     /// `Receiver` goes away.
-    pub fn poll_cancel(&mut self, cx: &mut Context<'_>) -> Poll<()> {
-        self.inner.poll_cancel(cx)
+    pub fn poll_canceled(&mut self, cx: &mut Context<'_>) -> Poll<()> {
+        self.inner.poll_canceled(cx)
     }
 
     /// Tests to see whether this `Sender`'s corresponding `Receiver`
     /// has been dropped.
     ///
-    /// Unlike [`poll_cancel`](Sender::poll_cancel), this function does not
+    /// Unlike [`poll_canceled`](Sender::poll_canceled), this function does not
     /// enqueue a task for wakeup upon cancellation, but merely reports the
     /// current state, which may be subject to concurrent modification.
     pub fn is_canceled(&self) -> bool {
diff --git a/futures-util/src/future/remote_handle.rs b/futures-util/src/future/remote_handle.rs
index e3223c6c..4e30eede 100644
--- a/futures-util/src/future/remote_handle.rs
+++ b/futures-util/src/future/remote_handle.rs
@@ -80,7 +80,7 @@ impl<Fut: Future> Future for Remote<Fut> {
     type Output = ();
 
     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
-        if let Poll::Ready(_) = self.as_mut().tx().as_mut().unwrap().poll_cancel(cx) {
+        if let Poll::Ready(_) = self.as_mut().tx().as_mut().unwrap().poll_canceled(cx) {
             if !self.keep_running.load(Ordering::SeqCst) {
                 // Cancelled, bail out
                 return Poll::Ready(())


Test patch:
diff --git a/futures-channel/tests/oneshot.rs b/futures-channel/tests/oneshot.rs
index b36d25df..e6bc3f5f 100644
--- a/futures-channel/tests/oneshot.rs
+++ b/futures-channel/tests/oneshot.rs
@@ -12,11 +12,11 @@ fn smoke_poll() {
     let (mut tx, rx) = oneshot::channel::<u32>();
     let mut rx = Some(rx);
     let f = poll_fn(|cx| {
-        assert!(tx.poll_cancel(cx).is_pending());
-        assert!(tx.poll_cancel(cx).is_pending());
+        assert!(tx.poll_canceled(cx).is_pending());
+        assert!(tx.poll_canceled(cx).is_pending());
         drop(rx.take());
-        assert!(tx.poll_cancel(cx).is_ready());
-        assert!(tx.poll_cancel(cx).is_ready());
+        assert!(tx.poll_canceled(cx).is_ready());
+        assert!(tx.poll_canceled(cx).is_ready());
         Poll::Ready(())
     });
 
@@ -42,7 +42,7 @@ impl Future for WaitForCancel {
     type Output = ();
 
     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
-        self.tx.poll_cancel(cx)
+        self.tx.poll_canceled(cx)
     }
 }
 
@@ -72,7 +72,7 @@ fn cancel_lots() {
 fn cancel_after_sender_drop_doesnt_notify() {
     let (mut tx, rx) = oneshot::channel::<u32>();
     let mut cx = Context::from_waker(panic_waker_ref());
-    assert_eq!(tx.poll_cancel(&mut cx), Poll::Pending);
+    assert_eq!(tx.poll_canceled(&mut cx), Poll::Pending);
     drop(tx);
     drop(rx);
 }
@@ -86,7 +86,7 @@ fn close() {
             Poll::Ready(Err(_)) => {},
             _ => panic!(),
         };
-        assert!(tx.poll_cancel(cx).is_ready());
+        assert!(tx.poll_canceled(cx).is_ready());
         Poll::Ready(())
     }));
 }
diff --git a/futures/tests/ready_queue.rs b/futures/tests/ready_queue.rs
index ae0b7c35..80058005 100644
--- a/futures/tests/ready_queue.rs
+++ b/futures/tests/ready_queue.rs
@@ -81,15 +81,15 @@ fn dropping_ready_queue() {
 
         {
             let cx = &mut noop_context();
-            assert!(!tx1.poll_cancel(cx).is_ready());
-            assert!(!tx2.poll_cancel(cx).is_ready());
-            assert!(!tx3.poll_cancel(cx).is_ready());
+            assert!(!tx1.poll_canceled(cx).is_ready());
+            assert!(!tx2.poll_canceled(cx).is_ready());
+            assert!(!tx3.poll_canceled(cx).is_ready());
 
             drop(queue);
 
-            assert!(tx1.poll_cancel(cx).is_ready());
-            assert!(tx2.poll_cancel(cx).is_ready());
-            assert!(tx3.poll_cancel(cx).is_ready());
+            assert!(tx1.poll_canceled(cx).is_ready());
+            assert!(tx2.poll_canceled(cx).is_ready());
+            assert!(tx3.poll_canceled(cx).is_ready());
         }
     }));
 }