diff --git a/src/api/controller.rs b/src/api/controller.rs index 07a0d8f..8a4a5b5 100644 --- a/src/api/controller.rs +++ b/src/api/controller.rs @@ -4,7 +4,6 @@ //! server use crate::Result; -use std::sync::Arc; #[async_trait::async_trait] pub(crate) trait ControllerWorker { @@ -62,34 +61,4 @@ pub trait Controller : Sized + Send + Sync { fn blocking_recv(&self, rt: &tokio::runtime::Handle) -> Result { rt.block_on(self.recv()) } - - /// register a callback to be called for each received stream value - /// - /// this will spawn a new task on given runtime invoking [Self::recv] in loop and calling given - /// callback for each received value. a stop channel should be provided, and first value sent - /// into it will stop the worker loop. - /// - /// note: creating a callback handler will hold an Arc reference to the given controller, - /// preventing it from being dropped (and likely disconnecting). using the stop channel is - /// important for proper cleanup - fn callback( - self: &Arc, - rt: &tokio::runtime::Handle, - mut stop: tokio::sync::mpsc::UnboundedReceiver<()>, - mut cb: F - ) where - Self : 'static, - F : FnMut(T) + Sync + Send + 'static - { - let _self = self.clone(); - rt.spawn(async move { - loop { - tokio::select! { - Ok(data) = _self.recv() => cb(data), - Some(()) = stop.recv() => break, - else => break, - } - } - }); - } }