pi_async_runtime/
driving.rs1use crate::{
3 access::{self, BindingExitGuard},
4 instance::*,
5 lifecycle::RuntimeBinding,
6 mode::RuntimeMode,
7};
8use pi_async_executor::{DriveLease, ExecutorClock, ExecutorHooks, IdlePolicy, TurnResult};
9use pi_async_runtime_core::{
10 block_on::{BlockOnDriver, RootWakeState},
11 RuntimeBlockOn, RuntimeQuery, RuntimeStatus,
12};
13use pi_clock_manual::global::GlobalManualInstant;
14use std::future::Future;
15
16struct RuntimeDriver<'a, M, C, P, H>
17where
18 M: RuntimeMode,
19 C: ExecutorClock<Instant = GlobalManualInstant>,
20 P: IdlePolicy,
21 H: ExecutorHooks,
22{
23 data: &'a mut RuntimeData<M, C, P, H>,
24 lease: DriveLease,
25 last: Option<TurnResult>,
26 binding: &'a RuntimeBinding,
27 handle: &'a RuntimeHandle<C>,
28}
29impl<M, C, P, H> ConfiguredRuntime<M, C, P, H>
30where
31 M: RuntimeMode,
32 C: ExecutorClock<Instant = GlobalManualInstant>,
33 P: IdlePolicy,
34 H: ExecutorHooks,
35{
36 pub fn run_once(&mut self) -> pi_result::Result<TurnResult> {
39 runtime_once_inner(self)
40 }
41 pub fn run(&mut self) -> pi_result::Result<()> {
43 runtime_run_inner(self)
44 }
45}
46impl<C: ExecutorClock<Instant = GlobalManualInstant>> RuntimeBlockOn for RuntimeHandle<C> {
47 fn block_on<F: Future>(&self, future: F) -> F::Output {
50 handle_block_on_inner(self, future)
51 }
52}
53impl<M, C, P, H> RuntimeBlockOn for ConfiguredRuntime<M, C, P, H>
54where
55 M: RuntimeMode,
56 C: ExecutorClock<Instant = GlobalManualInstant>,
57 P: IdlePolicy,
58 H: ExecutorHooks,
59{
60 fn block_on<F: Future>(&self, future: F) -> F::Output {
64 runtime_block_on_inner(self, future)
65 }
66}
67impl<M, C, P, H> BlockOnDriver for RuntimeDriver<'_, M, C, P, H>
68where
69 M: RuntimeMode,
70 C: ExecutorClock<Instant = GlobalManualInstant>,
71 P: IdlePolicy,
72 H: ExecutorHooks,
73{
74 fn turn(&mut self) -> bool {
75 runtime_driver_turn_inner(self)
76 }
77 fn park(&mut self, root: &RootWakeState) {
78 runtime_driver_park_inner(self, root)
79 }
80}
81include!("driving_inner.rs");