aboutsummaryrefslogtreecommitdiff
path: root/src/fs/mocks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/mocks.rs')
-rw-r--r--src/fs/mocks.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/fs/mocks.rs b/src/fs/mocks.rs
index 68ef4f3..aa01e24 100644
--- a/src/fs/mocks.rs
+++ b/src/fs/mocks.rs
@@ -81,7 +81,7 @@ impl Write for &'_ MockFile {
}
}
-thread_local! {
+tokio_thread_local! {
static QUEUE: RefCell<VecDeque<Box<dyn FnOnce() + Send>>> = RefCell::new(VecDeque::new())
}
@@ -105,6 +105,21 @@ where
JoinHandle { rx }
}
+pub(super) fn spawn_mandatory_blocking<F, R>(f: F) -> Option<JoinHandle<R>>
+where
+ F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
+{
+ let (tx, rx) = oneshot::channel();
+ let task = Box::new(move || {
+ let _ = tx.send(f());
+ });
+
+ QUEUE.with(|cell| cell.borrow_mut().push_back(task));
+
+ Some(JoinHandle { rx })
+}
+
impl<T> Future for JoinHandle<T> {
type Output = Result<T, io::Error>;