1#[cfg(feature = "test-util")]
2use crate::runtime::scheduler;
3use crate::runtime::task::{self, Task};
4use crate::runtime::Handle;
5
6/// `task::Schedule` implementation that does nothing (except some bookkeeping
7/// in test-util builds). This is unique to the blocking scheduler as tasks
8/// scheduled are not really futures but blocking operations.
9///
10/// We avoid storing the task by forgetting it in `bind` and re-materializing it
11/// in `release`.
12pub(crate) struct BlockingSchedule {
13 #[cfg(feature = "test-util")]
14 handle: Handle,
15}
16
17impl BlockingSchedule {
18 #[cfg_attr(not(feature = "test-util"), allow(unused_variables))]
19 pub(crate) fn new(handle: &Handle) -> Self {
20 #[cfg(feature = "test-util")]
21 {
22 match &handle.inner {
23 scheduler::Handle::CurrentThread(handle) => {
24 handle.driver.clock.inhibit_auto_advance();
25 }
26 #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
27 scheduler::Handle::MultiThread(_) => {}
28 #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
29 scheduler::Handle::MultiThreadAlt(_) => {}
30 }
31 }
32 BlockingSchedule {
33 #[cfg(feature = "test-util")]
34 handle: handle.clone(),
35 }
36 }
37}
38
39impl task::Schedule for BlockingSchedule {
40 fn release(&self, _task: &Task<Self>) -> Option<Task<Self>> {
41 #[cfg(feature = "test-util")]
42 {
43 match &self.handle.inner {
44 scheduler::Handle::CurrentThread(handle) => {
45 handle.driver.clock.allow_auto_advance();
46 handle.driver.unpark();
47 }
48 #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
49 scheduler::Handle::MultiThread(_) => {}
50 #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
51 scheduler::Handle::MultiThreadAlt(_) => {}
52 }
53 }
54 None
55 }
56
57 fn schedule(&self, _task: task::Notified<Self>) {
58 unreachable!();
59 }
60}
61