fix: pass runtime for callback spawning

This commit is contained in:
əlemi 2023-08-18 03:58:42 +02:00
parent 85bd3c4535
commit 853d754d8b

View file

@ -41,11 +41,11 @@ pub trait Controller<T> : Sized + Send + Sync {
async fn send(&self, x: Self::Input) -> Result<(), Error>; async fn send(&self, x: Self::Input) -> Result<(), Error>;
async fn recv(&self) -> Result<T, Error>; async fn recv(&self) -> Result<T, Error>;
fn callback<F>(self: Arc<Self>, mut cb: F) fn callback<F>(self: Arc<Self>, rt: &tokio::runtime::Runtime, mut cb: F)
where Self : 'static, F : FnMut(T) + Sync + Send + 'static where Self : 'static, F : FnMut(T) + Sync + Send + 'static
{ {
let x = Arc::new(self); let x = Arc::new(self);
tokio::spawn(async move { rt.spawn(async move {
while let Ok(data) = x.recv().await { while let Ok(data) = x.recv().await {
cb(data) cb(data)
} }