use std::cell::RefCell;
use super::Vm;
thread_local! {
pub(super) static CURRENT_ASYNC_BUILTIN_CHILD_VM: RefCell<Vec<Vm>> =
const { RefCell::new(Vec::new()) };
}
pub fn clone_async_builtin_child_vm() -> Option<Vm> {
CURRENT_ASYNC_BUILTIN_CHILD_VM.with(|slot| slot.borrow().last().map(|vm| vm.child_vm()))
}
pub struct AsyncBuiltinChildVmGuard;
pub fn install_async_builtin_child_vm(vm: Vm) -> AsyncBuiltinChildVmGuard {
CURRENT_ASYNC_BUILTIN_CHILD_VM.with(|slot| {
slot.borrow_mut().push(vm);
});
AsyncBuiltinChildVmGuard
}
impl Drop for AsyncBuiltinChildVmGuard {
fn drop(&mut self) {
CURRENT_ASYNC_BUILTIN_CHILD_VM.with(|slot| {
slot.borrow_mut().pop();
});
}
}
#[deprecated(
note = "use clone_async_builtin_child_vm() — take/restore serialized concurrent callers"
)]
pub fn take_async_builtin_child_vm() -> Option<Vm> {
clone_async_builtin_child_vm()
}
#[deprecated(note = "clone_async_builtin_child_vm does not need a matching restore call")]
pub fn restore_async_builtin_child_vm(_vm: Vm) {
CURRENT_ASYNC_BUILTIN_CHILD_VM.with(|slot| {
let _ = slot;
});
}