From 8a75b980db825745caa2f45ae3b38ea365800957 Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Wed, 13 Nov 2024 14:54:30 -0500 Subject: [PATCH 1/2] Document cancel-safety of FuturesUnordered::poll_next --- futures-util/src/stream/futures_unordered/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index 913e260fd..0fcf92cb3 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -53,6 +53,13 @@ use self::ready_to_run_queue::{Dequeue, ReadyToRunQueue}; /// /// This type is only available when the `std` or `alloc` feature of this /// library is activated, and it is activated by default. +/// +/// # Cancel safety +/// +/// This type is cancellation-safe. If [`poll_next`](Stream::poll_next) is +/// called (either directly or via [`crate::StreamExt::next`]) and it returns +/// [`Poll::Pending`], no values will be dropped if `poll_next` is not called +/// again. #[must_use = "streams do nothing unless polled"] pub struct FuturesUnordered { ready_to_run_queue: Arc>, From ea5b0ea5414e591de23bfef32c2b8c5e640892da Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Mon, 2 Dec 2024 13:09:50 -0500 Subject: [PATCH 2/2] Conditionalize cancel-safety on Future cancel safety --- futures-util/src/stream/futures_unordered/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index 0fcf92cb3..7f7a00018 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -56,10 +56,11 @@ use self::ready_to_run_queue::{Dequeue, ReadyToRunQueue}; /// /// # Cancel safety /// -/// This type is cancellation-safe. If [`poll_next`](Stream::poll_next) is -/// called (either directly or via [`crate::StreamExt::next`]) and it returns -/// [`Poll::Pending`], no values will be dropped if `poll_next` is not called -/// again. +/// This type is cancellation-safe when the inner [`Future`] is +/// cancellation-safe. If the future type is cancellation-safe, and +/// [`poll_next`](Stream::poll_next) is called (either directly or via +/// [`crate::StreamExt::next`]) and returns [`Poll::Pending`], no values will be +/// dropped if `poll_next` is not called again. #[must_use = "streams do nothing unless polled"] pub struct FuturesUnordered { ready_to_run_queue: Arc>,