use std::cell::Cell;
use std::sync::OnceLock;
use std::time::Instant;
static WAKER: OnceLock<fn()> = OnceLock::new();
pub fn set_waker(waker: fn()) {
let _ = WAKER.set(waker);
redjs::web::set_wake_hook(wake);
}
pub fn wake() {
if let Some(waker) = WAKER.get() {
waker();
}
}
thread_local! {
static WAKE_AT: Cell<Option<Instant>> = const { Cell::new(None) };
}
pub fn wake_at(at: Instant) {
WAKE_AT.with(|w| w.set(Some(w.get().map_or(at, |t| t.min(at)))));
}
pub fn take_wake_at() -> Option<Instant> {
WAKE_AT.with(Cell::take)
}