Temporary commit to try fix halting
This commit is contained in:
23
orchid-base/src/testing.rs
Normal file
23
orchid-base/src/testing.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
#![cfg(any(feature = "mocks", test))]
|
||||
|
||||
use std::future::ready;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct AsyncMonitor<E: 'static>(Rc<dyn Fn(E) -> Pin<Box<dyn Future<Output = ()>>>>);
|
||||
impl<E: 'static> AsyncMonitor<E> {
|
||||
pub fn new<F: AsyncFn(E) -> () + '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<E: 'static> Default for AsyncMonitor<E> {
|
||||
fn default() -> Self { Self(Rc::new(|_| Box::pin(ready(())))) }
|
||||
}
|
||||
impl<E: 'static> Clone for AsyncMonitor<E> {
|
||||
fn clone(&self) -> Self { Self(self.0.clone()) }
|
||||
}
|
||||
Reference in New Issue
Block a user