Skip to main content

rquickjs_core/
runtime.rs

1//! QuickJS runtime related types.
2
3mod base;
4mod exotic;
5pub(crate) mod opaque;
6pub(crate) mod raw;
7mod userdata;
8
9#[cfg(feature = "futures")]
10mod r#async;
11#[cfg(feature = "futures")]
12pub(crate) mod schedular;
13#[cfg(feature = "futures")]
14mod spawner;
15#[cfg(feature = "futures")]
16pub use spawner::DriveFuture;
17
18use alloc::boxed::Box;
19pub use base::{Runtime, WeakRuntime};
20pub use userdata::{UserDataError, UserDataGuard};
21
22#[cfg(feature = "futures")]
23pub(crate) use r#async::InnerRuntime;
24#[cfg(feature = "futures")]
25pub use r#async::{AsyncRuntime, AsyncWeakRuntime};
26
27use crate::value::promise::PromiseHookType;
28use crate::{Ctx, Value};
29
30/// The type of the promise hook.
31#[cfg(not(feature = "parallel"))]
32pub type PromiseHook =
33    Box<dyn for<'a> Fn(Ctx<'a>, PromiseHookType, Value<'a>, Value<'a>) + 'static>;
34/// The type of the promise hook.
35#[cfg(feature = "parallel")]
36pub type PromiseHook =
37    Box<dyn for<'a> Fn(Ctx<'a>, PromiseHookType, Value<'a>, Value<'a>) + Send + 'static>;
38
39/// The type of the promise rejection tracker.
40#[cfg(not(feature = "parallel"))]
41pub type RejectionTracker = Box<dyn for<'a> Fn(Ctx<'a>, Value<'a>, Value<'a>, bool) + 'static>;
42/// The type of the promise rejection tracker.
43#[cfg(feature = "parallel")]
44pub type RejectionTracker =
45    Box<dyn for<'a> Fn(Ctx<'a>, Value<'a>, Value<'a>, bool) + Send + 'static>;
46
47/// The type of the interrupt handler.
48#[cfg(not(feature = "parallel"))]
49pub type InterruptHandler = Box<dyn FnMut() -> bool + 'static>;
50/// The type of the interrupt handler.
51#[cfg(feature = "parallel")]
52pub type InterruptHandler = Box<dyn FnMut() -> bool + Send + 'static>;
53
54/// A struct with information about the runtimes memory usage.
55pub type MemoryUsage = crate::qjs::JSMemoryUsage;