Skip to content

Commit 279e8b0

Browse files
authored
sync: document spurious failures on poll_recv (#4117)
1 parent e9f6fae commit 279e8b0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tokio/src/sync/mpsc/bounded.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ impl<T> Receiver<T> {
195195
/// This method returns the [`Disconnected`] error if the channel is
196196
/// currently empty, and there are no outstanding [senders] or [permits].
197197
///
198+
/// Unlike the [`poll_recv`] method, this method will never return an
199+
/// [`Empty`] error spuriously.
200+
///
198201
/// [`Empty`]: crate::sync::mpsc::error::TryRecvError::Empty
199202
/// [`Disconnected`]: crate::sync::mpsc::error::TryRecvError::Disconnected
203+
/// [`poll_recv`]: Self::poll_recv
200204
/// [senders]: crate::sync::mpsc::Sender
201205
/// [permits]: crate::sync::mpsc::Permit
202206
///
@@ -331,7 +335,7 @@ impl<T> Receiver<T> {
331335
/// This method returns:
332336
///
333337
/// * `Poll::Pending` if no messages are available but the channel is not
334-
/// closed.
338+
/// closed, or if a spurious failure happens.
335339
/// * `Poll::Ready(Some(message))` if a message is available.
336340
/// * `Poll::Ready(None)` if the channel has been closed and all messages
337341
/// sent before it was closed have been received.
@@ -341,6 +345,12 @@ impl<T> Receiver<T> {
341345
/// receiver, or when the channel is closed. Note that on multiple calls to
342346
/// `poll_recv`, only the `Waker` from the `Context` passed to the most
343347
/// recent call is scheduled to receive a wakeup.
348+
///
349+
/// If this method returns `Poll::Pending` due to a spurious failure, then
350+
/// the `Waker` will be notified when the situation causing the spurious
351+
/// failure has been resolved. Note that receiving such a wakeup does not
352+
/// guarantee that the next call will succeed — it could fail with another
353+
/// spurious failure.
344354
pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<T>> {
345355
self.chan.recv(cx)
346356
}

tokio/src/sync/mpsc/unbounded.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ impl<T> UnboundedReceiver<T> {
137137
/// This method returns the [`Disconnected`] error if the channel is
138138
/// currently empty, and there are no outstanding [senders] or [permits].
139139
///
140+
/// Unlike the [`poll_recv`] method, this method will never return an
141+
/// [`Empty`] error spuriously.
142+
///
140143
/// [`Empty`]: crate::sync::mpsc::error::TryRecvError::Empty
141144
/// [`Disconnected`]: crate::sync::mpsc::error::TryRecvError::Disconnected
145+
/// [`poll_recv`]: Self::poll_recv
142146
/// [senders]: crate::sync::mpsc::Sender
143147
/// [permits]: crate::sync::mpsc::Permit
144148
///
@@ -212,7 +216,7 @@ impl<T> UnboundedReceiver<T> {
212216
/// This method returns:
213217
///
214218
/// * `Poll::Pending` if no messages are available but the channel is not
215-
/// closed.
219+
/// closed, or if a spurious failure happens.
216220
/// * `Poll::Ready(Some(message))` if a message is available.
217221
/// * `Poll::Ready(None)` if the channel has been closed and all messages
218222
/// sent before it was closed have been received.
@@ -222,6 +226,12 @@ impl<T> UnboundedReceiver<T> {
222226
/// receiver, or when the channel is closed. Note that on multiple calls to
223227
/// `poll_recv`, only the `Waker` from the `Context` passed to the most
224228
/// recent call is scheduled to receive a wakeup.
229+
///
230+
/// If this method returns `Poll::Pending` due to a spurious failure, then
231+
/// the `Waker` will be notified when the situation causing the spurious
232+
/// failure has been resolved. Note that receiving such a wakeup does not
233+
/// guarantee that the next call will succeed — it could fail with another
234+
/// spurious failure.
225235
pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<T>> {
226236
self.chan.recv(cx)
227237
}

0 commit comments

Comments
 (0)