use std::cell::Cell;
use yog_hot_reload::ModuleGeneration;
thread_local! {
static RUNNING: Cell<Option<ModuleGeneration>> = const { Cell::new(None) };
}
pub(crate) struct Running(Option<ModuleGeneration>);
pub(crate) fn enter(generation: ModuleGeneration) -> Running {
Running(RUNNING.replace(Some(generation)))
}
impl Drop for Running {
fn drop(&mut self) {
RUNNING.set(self.0);
}
}
pub(crate) fn caller() -> Option<ModuleGeneration> {
RUNNING
.get()
.or_else(|| super::owner().map(|m| m.generation()))
}