pub struct HookEventBroadcaster { /* private fields */ }Expand description
In-process pub/sub broker for hook events. Lives on
GrpcLocalService so every handler
shares the same broker and a subscribe_hook_events stream and a
respond_to_hook reply meet on the same correlator.
Implementations§
Source§impl HookEventBroadcaster
impl HookEventBroadcaster
pub fn new() -> Self
Sourcepub fn subscribe(&self) -> Receiver<ProtoHookEvent>
pub fn subscribe(&self) -> Receiver<ProtoHookEvent>
Subscribe a fresh stream. Each call returns its own
mpsc::Receiver backed by a forwarding task that drains the
underlying broadcast::Receiver. The mpsc shape lets us close
the stream cleanly when the subscriber drops, and lets the
Lagged error close the stream rather than panicking.
Sourcepub fn emit(
&self,
event_name: impl Into<String>,
payload_json: impl Into<String>,
) -> String
pub fn emit( &self, event_name: impl Into<String>, payload_json: impl Into<String>, ) -> String
Emit a fresh hook event. Returns the hook_event_id the
caller should pass to Self::await_response. The id is a
stringified UUIDv4 so it survives JSON round-trips intact.
payload_json is delivered verbatim — schema validation lives
in the catalog (see GetHookEventSchema) and is the caller’s
responsibility for now.
Sourcepub fn emit_and_wait(
&self,
event_name: impl Into<String>,
payload_json: impl Into<String>,
timeout: Duration,
) -> (String, EmitWaiter)
pub fn emit_and_wait( &self, event_name: impl Into<String>, payload_json: impl Into<String>, timeout: Duration, ) -> (String, EmitWaiter)
Register a single-shot response slot for hook_event_id and
emit at the same time. Returns the id and a future that
resolves to the hook’s reply (or times out).
Use this from the capture/merge code paths when you both want to fire the event and wait for the reply atomically.
Sourcepub async fn await_response(
&self,
hook_event_id: &str,
timeout: Duration,
) -> Option<HookResponse>
pub async fn await_response( &self, hook_event_id: &str, timeout: Duration, ) -> Option<HookResponse>
Await a reply for hook_event_id with a deadline. Returns
None when the deadline elapses before a hook responds (the
emit caller’s “no hook acted on this in time” branch).
The slot must have been reserved via Self::emit_and_wait
— calling this for a never-registered id resolves to None
immediately.
Sourcepub fn deliver_response(
&self,
hook_event_id: &str,
response: HookResponse,
) -> bool
pub fn deliver_response( &self, hook_event_id: &str, response: HookResponse, ) -> bool
Deliver a hook reply to the in-flight emit waiting on
hook_event_id. Called by the RespondToHook handler.
Returns true when the reply was delivered (a waiter was
present); false when no waiter is registered (timed out, or
already replied).
Trait Implementations§
Source§impl Clone for HookEventBroadcaster
impl Clone for HookEventBroadcaster
Source§fn clone(&self) -> HookEventBroadcaster
fn clone(&self) -> HookEventBroadcaster
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HookEventBroadcaster
impl RefUnwindSafe for HookEventBroadcaster
impl Send for HookEventBroadcaster
impl Sync for HookEventBroadcaster
impl Unpin for HookEventBroadcaster
impl UnsafeUnpin for HookEventBroadcaster
impl UnwindSafe for HookEventBroadcaster
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request