use crate::context::record::DriveScope;
use std::{
future::Future,
pin::Pin,
sync::{atomic::AtomicBool, Arc},
task::{Context, Poll, Wake, Waker},
thread::Thread,
};
pub trait RuntimeBlockOn {
fn block_on<F: Future>(&self, future: F) -> F::Output;
}
pub struct RootWakeState {
thread: Thread,
notified: AtomicBool,
}
impl RootWakeState {
pub fn is_notified(&self) -> bool {
root_notified_inner(self)
}
pub fn park(&self) {
root_park_inner(self)
}
}
impl Wake for RootWakeState {
fn wake(self: Arc<Self>) {
root_wake_inner(&self)
}
fn wake_by_ref(self: &Arc<Self>) {
root_wake_inner(self)
}
}
pub trait BlockOnDriver {
fn turn(&mut self) -> bool;
fn park(&mut self, root: &RootWakeState);
}
pub fn block_on_root<F: Future>(future: F) -> F::Output {
root_block_on_inner(future)
}
pub fn block_on_with_driver<F: Future, D: BlockOnDriver>(future: F, driver: &mut D) -> F::Output {
driver_block_on_inner(future, driver)
}
include!("block_on_inner.rs");