#![cfg(any(feature = "mocks", test))] use std::future::ready; use std::pin::Pin; use std::rc::Rc; pub struct AsyncMonitor(Rc Pin>>>); impl AsyncMonitor { pub fn new () + 'static>(f: F) -> Self { let f_rc = Rc::new(f); AsyncMonitor(Rc::new(move |e| { let f_rc = f_rc.clone(); Box::pin(async move { f_rc(e).await }) })) } pub async fn notify(&self, e: E) -> () { (self.0)(e).await } } impl Default for AsyncMonitor { fn default() -> Self { Self(Rc::new(|_| Box::pin(ready(())))) } } impl Clone for AsyncMonitor { fn clone(&self) -> Self { Self(self.0.clone()) } }