Skip to main content

Module plugin_events

Module plugin_events 

Source
Expand description

Cross-thread event bus for plugins, modules and add-ons.

Something outside a script call pushes events at the engine from whichever thread it likes: a worker delivering what it watched for, a call body handing work past its own return, a promise settling in a page. This bus is where those events wait for the tick that drains them.

An event arrives in one of two forms. A portable plugin lives across a serialized boundary, so its event is encoded bytes. Code that shares the engine’s address space (a runtime module, a browser add-on) hands over the value itself, and nothing is encoded or decoded on its way through.

The core knows neither shape: the event is built from script-surface types this crate does not know, and the script layer that does know them registers the per-tick drain (lumen-script’s collect_plugin_events). What lives here is the bus itself, mirroring the external typed-property bus in crate::property_store, so crate::tick::work_pending can count undrained events as pending work and a parked app wakes to take them.

Enums§

QueuedEvent
One event waiting on the bus, in the form it was pushed in.

Functions§

discard_plugin_events
Empties the bus, throwing away whatever it holds.
drain_plugin_events
Take every queued event, in arrival order. Returns the empty vector when the channel was never initialised, is empty, or its lock is poisoned.
init_plugin_events
Idempotently initialises the plugin-event channel. Safe to call multiple times.
plugin_events_pending
Whether the bus currently holds undrained events.
push_plugin_event
Queue one encoded plugin event from any thread. Picked up on the next tick by the script layer’s drain; a parked event loop is woken to run that tick when a waker is installed (set_plugin_event_waker).
push_plugin_value
Queue one event as the value itself, from any thread, for code that shares the engine’s address space. Delivered and woken for exactly like push_plugin_event; the drain takes it back as the type it was pushed as.
set_plugin_event_waker
Install the waker a push nudges, so an event arriving while the app sits parked in its event loop’s Wait state triggers the tick that drains it instead of waiting for an unrelated wake. The backends install it beside the crate::app::EventLoopWaker resource; a later install replaces the earlier one, because a process can run apps in sequence and the bus belongs to whichever loop is live.