diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-01 11:03:05 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-01 11:03:05 +0000 |
commit | c26cd85ccebf317c2021f6e0fa55fd6c8a14a802 (patch) | |
tree | 84073e6bc26e40362df1df64183d1a6e91f7e431 /src/fs/mocks.rs | |
parent | d6160b5e7081cd934c2d566c5da230627b0f46ba (diff) | |
parent | 67f287733f1d477619a50533f54676c7ffb41c25 (diff) | |
download | tokio-c26cd85ccebf317c2021f6e0fa55fd6c8a14a802.tar.gz |
Snap for 9550355 from 67f287733f1d477619a50533f54676c7ffb41c25 to sdk-releaseplatform-tools-34.0.0platform-tools-33.0.4
Change-Id: I828c29b2fcfc9d028082cd2f4b13c5edfe64bb91
Diffstat (limited to 'src/fs/mocks.rs')
-rw-r--r-- | src/fs/mocks.rs | 17 |
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>; |