diff --git a/src/tools/broadcast_future.rs b/src/tools/broadcast_future.rs index 94aedf18..88b7aaab 100644 --- a/src/tools/broadcast_future.rs +++ b/src/tools/broadcast_future.rs @@ -62,14 +62,16 @@ impl BroadcastData { } } +type SourceFuture = Pin> + Send>>; + +struct BroadCastFutureBinding { + broadcast: BroadcastData, + future: Option>, +} + /// Broadcast future results to registered listeners pub struct BroadcastFuture { - inner: Arc< - Mutex<( - BroadcastData, - Option> + Send>>>, - )>, - >, + inner: Arc>>, } impl BroadcastFuture { @@ -77,7 +79,11 @@ impl BroadcastFuture { /// /// The result of the future is sent to all registered listeners. pub fn new(source: Box> + Send>) -> Self { - Self { inner: Arc::new(Mutex::new((BroadcastData::new(), Some(Pin::from(source))))) } + let inner = BroadCastFutureBinding { + broadcast: BroadcastData::new(), + future: Some(Pin::from(source)), + }; + Self { inner: Arc::new(Mutex::new(inner)) } } /// Creates a new instance with a oneshot channel as trigger @@ -92,29 +98,17 @@ impl BroadcastFuture { } fn notify_listeners( - inner: Arc< - Mutex<( - BroadcastData, - Option> + Send>>>, - )>, - >, + inner: Arc>>, result: Result, ) { let mut data = inner.lock().unwrap(); - data.0.notify_listeners(result); + data.broadcast.notify_listeners(result); } - fn spawn( - inner: Arc< - Mutex<( - BroadcastData, - Option> + Send>>>, - )>, - >, - ) -> impl Future> { + fn spawn(inner: Arc>>) -> impl Future> { let mut data = inner.lock().unwrap(); - if let Some(source) = data.1.take() { + if let Some(source) = data.future.take() { let inner1 = inner.clone(); @@ -127,7 +121,7 @@ impl BroadcastFuture { tokio::spawn(task); } - data.0.listen() + data.broadcast.listen() } /// Register a listener