Skip to main content

DispatchToEventLoopCallback

Type Alias DispatchToEventLoopCallback 

Source
pub type DispatchToEventLoopCallback = Option<unsafe extern "C" fn(*mut c_void, *mut u8) -> bool>;
Expand description

Callback to dispatch a JS::Dispatchable to a JSContext’s thread’s event loop.

The DispatchToEventLoopCallback set on a particular JSContext must accept JS::Dispatchable instances and arrange for their run methods to be called eventually on the JSContext’s thread. This is used for cross-thread dispatch, so the callback itself must be safe to call from any thread. It cannot trigger a GC.

The DelayedDispatchToEventLoopCallback in addition takes a delay, and it must accept JS::Dispatchable instances and arrange for their run methods to be called after the delay on the JSContext’s thread. The embeddings must have its own timeout manager to handle the delay. If a timeout manager is not available for given context, it should return false, optionally with a warning message printed.

The callback accepts a closure that is the same as the one given by the call to JS::InitAsyncTaskCallbacks.

If the callback returns true, it must eventually run the given Dispatchable; otherwise, SpiderMonkey may leak memory or hang.

The callback may return false to indicate that the JSContext’s thread is shutting down and is no longer accepting runnables. Shutting down is a one-way transition: once the callback has rejected a runnable, it must reject all subsequently submitted runnables as well.

Aliased Type§

pub enum DispatchToEventLoopCallback {
    None,
    Some(unsafe extern "C" fn(*mut c_void, *mut u8) -> bool),
}

Variants§

§1.0.0

None

No value.

§1.0.0

Some(unsafe extern "C" fn(*mut c_void, *mut u8) -> bool)

Some value of type T.