use crate::{
access::{self, BindingExitGuard},
instance::*,
lifecycle::RuntimeBinding,
mode::RuntimeMode,
};
use pi_async_executor::{DriveLease, ExecutorClock, ExecutorHooks, IdlePolicy, TurnResult};
use pi_async_runtime_core::{
block_on::{BlockOnDriver, RootWakeState},
RuntimeBlockOn, RuntimeQuery, RuntimeStatus,
};
use pi_clock_manual::global::GlobalManualInstant;
use std::future::Future;
struct RuntimeDriver<'a, M, C, P, H>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
{
data: &'a mut RuntimeData<M, C, P, H>,
lease: DriveLease,
last: Option<TurnResult>,
binding: &'a RuntimeBinding,
handle: &'a RuntimeHandle<C>,
}
impl<M, C, P, H> ConfiguredRuntime<M, C, P, H>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
{
pub fn run_once(&mut self) -> pi_result::Result<TurnResult> {
runtime_once_inner(self)
}
pub fn run(&mut self) -> pi_result::Result<()> {
runtime_run_inner(self)
}
}
impl<C: ExecutorClock<Instant = GlobalManualInstant>> RuntimeBlockOn for RuntimeHandle<C> {
fn block_on<F: Future>(&self, future: F) -> F::Output {
handle_block_on_inner(self, future)
}
}
impl<M, C, P, H> RuntimeBlockOn for ConfiguredRuntime<M, C, P, H>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
{
fn block_on<F: Future>(&self, future: F) -> F::Output {
runtime_block_on_inner(self, future)
}
}
impl<M, C, P, H> BlockOnDriver for RuntimeDriver<'_, M, C, P, H>
where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
{
fn turn(&mut self) -> bool {
runtime_driver_turn_inner(self)
}
fn park(&mut self, root: &RootWakeState) {
runtime_driver_park_inner(self, root)
}
}
include!("driving_inner.rs");