use std::pin::Pin;
use std::time::{Duration, Instant};
use crate::DriverContext;
use dope_core::driver::token::Token;
use dope_core::io::Event;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Idle {
Busy,
Park(Option<Instant>),
}
impl Idle {
pub fn reduce(self, other: Self) -> Self {
match (self, other) {
(Idle::Busy, _) | (_, Idle::Busy) => Idle::Busy,
(Idle::Park(a), Idle::Park(b)) => Idle::Park(match (a, b) {
(Some(x), Some(y)) => Some(x.min(y)),
(a, b) => a.or(b),
}),
}
}
}
pub trait Dispatcher<'d>: Sized {
const SHUTDOWN_DRAIN: Duration = Duration::from_secs(2);
fn dispatch(self: Pin<&mut Self>, ev: Event<'d>, driver: &mut DriverContext<'_, 'd>);
fn activate(self: Pin<&mut Self>, target: Token, driver: &mut DriverContext<'_, 'd>);
fn pre_park(self: Pin<&mut Self>, driver: &mut DriverContext<'_, 'd>);
fn idle(self: Pin<&Self>) -> Idle;
fn shutdown(self: Pin<&mut Self>, driver: &mut DriverContext<'_, 'd>) {
let _ = driver;
}
}