pi_async_runtime/
capabilities.rs1use crate::{instance::*, mode::RuntimeMode};
3use pi_async_executor::{ExecutorClock, ExecutorHooks, IdlePolicy};
4use pi_async_runtime_core::{
5 CloseRequestStatus, CloseState, IdleState, RuntimeControl, RuntimeId, RuntimeQuery,
6 RuntimeStatus, RuntimeTime, RuntimeWait, Sleep, Timeout, TimeoutOn,
7};
8use pi_clock_manual::global::GlobalManualInstant;
9use std::{future::Future, time::Duration};
10impl<C> RuntimeTime for RuntimeHandle<C>
11where
12 C: ExecutorClock<Instant = GlobalManualInstant>,
13{
14 type Timer = RuntimeTimerAccess<C>;
15 fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> {
16 Timeout::new(self.shared().inner.timer_access(), duration)
17 }
18 fn timeout_on<F: Future>(&self, future: F, duration: Duration) -> TimeoutOn<Self::Timer, F> {
19 TimeoutOn::new(self.shared().inner.timer_access(), future, duration)
20 }
21 fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> {
22 Sleep::new(self.shared().inner.timer_access(), duration)
23 }
24}
25impl<C> RuntimeWait for RuntimeHandle<C> where C: ExecutorClock<Instant = GlobalManualInstant> {}
26impl<C> RuntimeQuery for RuntimeHandle<C>
27where
28 C: ExecutorClock<Instant = GlobalManualInstant>,
29{
30 fn id(&self) -> RuntimeId {
31 self.shared().inner.id()
32 }
33 fn status(&self) -> RuntimeStatus {
34 self.shared().inner.status()
35 }
36 fn is_driving(&self) -> bool {
37 self.shared().inner.is_driving()
38 }
39 fn last_idle_state(&self) -> IdleState {
40 self.shared().inner.last_idle_state()
41 }
42 fn close_state(&self) -> CloseState {
43 self.shared().inner.close_state()
44 }
45 fn external_task_count(&self) -> usize {
46 self.shared().inner.external_task_count()
47 }
48 fn internal_task_count(&self) -> usize {
49 self.shared().inner.internal_task_count()
50 }
51 fn timer_registration_count(&self) -> usize {
52 self.shared().inner.timer_registration_count()
53 }
54 fn idle_task_count(&self) -> usize {
55 self.shared().inner.idle_task_count()
56 }
57 fn in_flight_task_count(&self) -> usize {
58 self.shared().inner.in_flight_task_count()
59 }
60 fn waiting_for_wake_count(&self) -> usize {
61 self.shared().inner.waiting_for_wake_count()
62 }
63 fn pending_cancel_task_count(&self) -> usize {
64 self.shared().inner.pending_cancel_task_count()
65 }
66}
67impl<C> RuntimeControl for RuntimeHandle<C>
68where
69 C: ExecutorClock<Instant = GlobalManualInstant>,
70{
71 fn request_close(&self) -> CloseRequestStatus {
72 self.shared().inner.request_close()
73 }
74}
75impl<M, C, P, H> RuntimeTime for ConfiguredRuntime<M, C, P, H>
76where
77 M: RuntimeMode,
78 C: ExecutorClock<Instant = GlobalManualInstant>,
79 P: IdlePolicy,
80 H: ExecutorHooks,
81{
82 type Timer = RuntimeTimerAccess<C>;
83 fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> {
84 Timeout::new(self.shared().inner.timer_access(), duration)
85 }
86 fn timeout_on<F: Future>(&self, future: F, duration: Duration) -> TimeoutOn<Self::Timer, F> {
87 TimeoutOn::new(self.shared().inner.timer_access(), future, duration)
88 }
89 fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> {
90 Sleep::new(self.shared().inner.timer_access(), duration)
91 }
92}
93impl<M, C, P, H> RuntimeWait for ConfiguredRuntime<M, C, P, H>
94where
95 M: RuntimeMode,
96 C: ExecutorClock<Instant = GlobalManualInstant>,
97 P: IdlePolicy,
98 H: ExecutorHooks,
99{
100}
101impl<M, C, P, H> RuntimeQuery for ConfiguredRuntime<M, C, P, H>
102where
103 M: RuntimeMode,
104 C: ExecutorClock<Instant = GlobalManualInstant>,
105 P: IdlePolicy,
106 H: ExecutorHooks,
107{
108 fn id(&self) -> RuntimeId {
109 self.shared().inner.id()
110 }
111 fn status(&self) -> RuntimeStatus {
112 self.shared().inner.status()
113 }
114 fn is_driving(&self) -> bool {
115 self.shared().inner.is_driving()
116 }
117 fn last_idle_state(&self) -> IdleState {
118 self.shared().inner.last_idle_state()
119 }
120 fn close_state(&self) -> CloseState {
121 self.shared().inner.close_state()
122 }
123 fn external_task_count(&self) -> usize {
124 self.shared().inner.external_task_count()
125 }
126 fn internal_task_count(&self) -> usize {
127 self.shared().inner.internal_task_count()
128 }
129 fn timer_registration_count(&self) -> usize {
130 self.shared().inner.timer_registration_count()
131 }
132 fn idle_task_count(&self) -> usize {
133 self.shared().inner.idle_task_count()
134 }
135 fn in_flight_task_count(&self) -> usize {
136 self.shared().inner.in_flight_task_count()
137 }
138 fn waiting_for_wake_count(&self) -> usize {
139 self.shared().inner.waiting_for_wake_count()
140 }
141 fn pending_cancel_task_count(&self) -> usize {
142 self.shared().inner.pending_cancel_task_count()
143 }
144}
145impl<M, C, P, H> RuntimeControl for ConfiguredRuntime<M, C, P, H>
146where
147 M: RuntimeMode,
148 C: ExecutorClock<Instant = GlobalManualInstant>,
149 P: IdlePolicy,
150 H: ExecutorHooks,
151{
152 fn request_close(&self) -> CloseRequestStatus {
153 self.shared().inner.request_close()
154 }
155}