From 178ececfe253914a772d56e29a0445e44a3ba1f5 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 9 Nov 2023 05:22:16 +0100 Subject: [PATCH] fix: remove callback from controller api --- src/api/controller.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) 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, - } - } - }); - } }