Skip to main content

Module events_host

Module events_host 

Source
Expand description

The event/hook guest world (PH7.8b).

An event-observing plugin implements the events-plugin world: it imports the events subscription API (host-provided) and host-services, and exports register-events (the host calls it once to drive subscription registration) and on-event (host→guest delivery). This module holds the fifth bindgen! (after plugin, picker-source-plugin, completion-source-plugin, grammar-plugin) for that world — the shared-types trick (with: points types + host-services at the plugin world’s generated modules so a crossed event value is the SAME Rust type WitBoundary round-trips, boundary_event.rs; PH7.3d precedent).

Async (unlike grammar). Event delivery is OFF the keystroke path: the host owns an mpsc and pushes each event to on-event on the plugin’s own task (§5.10.4). So the bindgen! sets exports: { default: async } — an on-event call suspends the guest stack, never pins the caller’s thread, and a slow handler can never freeze a keystroke or another subscriber (paramount #4). The per-plugin actor that drains the bus channel and drives on-event is the event_task bridge (PH7.8c).

Registration flow (the grammar register-grammar precedent): the host calls the guest’s register-events export; the guest calls the imported events.subscribe(filter, handler) host function; that records the declaration into the Store’s EventContributions (via the events::Host impl on PluginState, lib.rs); after the export returns, the host drains the subscriptions and wires each to the native EventBus (PH7.8c).

Structs§

EventContributions
The per-plugin accumulator the events::Host impl records into during register-events (lib.rs). Held in PluginState; drained by the host after the registration export returns (PH7.8c). record is the sync host-func body (it only pushes — it cannot trap), factored here (the GrammarContributions precedent) so recording is unit-testable without a PluginState / guest.
RecordedSubscription
One subscription a plugin declared through events.subscribe, recorded verbatim (the guest-chosen handler id + the WIT filter). The host drains these after register-events returns and wires each to the native EventBus (PH7.8c); the filter projects to native at wire time via boundary_event::project_event_filter.