Skip to content

Commit

Permalink
Rename oneshot:Sender::poll_cancel to poll_canceled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seanmonstar authored and cramertj committed Oct 10, 2019
1 parent 8f95de5 commit 3df6f46
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions futures-channel/src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>>,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions futures-channel/tests/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
});

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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(())
}));
}
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/remote_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
12 changes: 6 additions & 6 deletions futures/tests/ready_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}));
}
Expand Down

0 comments on commit 3df6f46

Please sign in to comment.