pi_async_runtime_core/
block_on.rs1use crate::context::record::DriveScope;
3use std::{
4 future::Future,
5 pin::Pin,
6 sync::{atomic::AtomicBool, Arc},
7 task::{Context, Poll, Wake, Waker},
8 thread::Thread,
9};
10
11pub trait RuntimeBlockOn {
12 fn block_on<F: Future>(&self, future: F) -> F::Output;
15}
16
17pub struct RootWakeState {
19 thread: Thread,
20 notified: AtomicBool,
21}
22impl RootWakeState {
23 pub fn is_notified(&self) -> bool {
26 root_notified_inner(self)
27 }
28 pub fn park(&self) {
30 root_park_inner(self)
31 }
32}
33impl Wake for RootWakeState {
34 fn wake(self: Arc<Self>) {
35 root_wake_inner(&self)
36 }
37 fn wake_by_ref(self: &Arc<Self>) {
38 root_wake_inner(self)
39 }
40}
41
42pub trait BlockOnDriver {
44 fn turn(&mut self) -> bool;
46 fn park(&mut self, root: &RootWakeState);
48}
49pub fn block_on_root<F: Future>(future: F) -> F::Output {
51 root_block_on_inner(future)
52}
53pub fn block_on_with_driver<F: Future, D: BlockOnDriver>(future: F, driver: &mut D) -> F::Output {
55 driver_block_on_inner(future, driver)
56}
57include!("block_on_inner.rs");