From d533e05adab6718daf5f191aacab2d5954f988d5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 25 Oct 2024 00:56:11 +0200 Subject: [PATCH] Update public location of broadcast Recv future Move from sync::broadcast to sync::futures. --- tokio/src/sync/broadcast.rs | 49 ++++++++++++++++++++++++------------- tokio/src/sync/mod.rs | 2 +- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/tokio/src/sync/broadcast.rs b/tokio/src/sync/broadcast.rs index 2e3f9689c..b97c44769 100644 --- a/tokio/src/sync/broadcast.rs +++ b/tokio/src/sync/broadcast.rs @@ -119,11 +119,10 @@ use crate::loom::cell::UnsafeCell; use crate::loom::sync::atomic::{AtomicBool, AtomicUsize}; use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard}; -use crate::runtime::coop::{cooperative, Coop}; +use crate::runtime::coop::cooperative; use crate::util::linked_list::{self, GuardedLinkedList, LinkedList}; use crate::util::WakeList; -use pin_project_lite::pin_project; use std::fmt; use std::future::Future; use std::marker::PhantomPinned; @@ -390,27 +389,43 @@ struct RecvGuard<'a, T> { slot: RwLockReadGuard<'a, Slot>, } -pin_project! { - /// Future for the [`Receiver::recv`] method. - pub struct Recv<'a, T> +pub(crate) mod future { + use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, + }; + + use pin_project_lite::pin_project; + + use crate::runtime::coop::Coop; + + use super::{error::RecvError, RecvInner}; + + pin_project! { + /// Future for the [`Receiver::recv`][super::Receiver::recv] method. + pub struct Recv<'a, T> + where + T: Clone, + { + #[pin] + pub(super) inner: Coop>, + } + } + + impl<'a, T> Future for Recv<'a, T> where T: Clone, { - #[pin] - inner: Coop>, + type Output = Result; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + self.project().inner.poll(cx) + } } } -impl<'a, T> Future for Recv<'a, T> -where - T: Clone, -{ - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.project().inner.poll(cx) - } -} +use self::future::Recv; /// Receive a value future. struct RecvInner<'a, T> { diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs index ddf996442..adfa7a7ef 100644 --- a/tokio/src/sync/mod.rs +++ b/tokio/src/sync/mod.rs @@ -449,7 +449,7 @@ cfg_sync! { /// Named future types. pub mod futures { - pub use super::notify::Notified; + pub use super::{notify::Notified, broadcast::future::Recv}; } mod barrier;