class
Rosegold::EventEmitter
- Rosegold::EventEmitter
- Reference
- Object
Overview
Typed event subscriptions shared by Bot and Client.
Handlers run synchronously in the emitting fiber. Use spawn for work that
waits for ticks or further packets so the reader can keep receiving events.
Direct Known Subclasses
Defined in:
rosegold/models/event_emitter.crInstance Method Summary
-
#emit_event(event : Event)
Calls handlers for this exact event type in registration order.
-
#event_handlers : Handlers
Registered handlers, grouped by exact event type.
-
#off(event_type : T.class, id : UUID) forall T
Removes the handler identified by id for event_type.
-
#on(event_type : T.class, id : UUID = UUID.random, &block : T -> ) forall T
Registers a handler and returns its UUID for removal with
#off. -
#once(event_type : T.class, &block : T -> ) forall T
Registers a handler for the next matching event and returns its UUID.
-
#wait_for(event_type : T.class, timeout : Time::Span = 5.seconds) forall T
Waits for the next matching event, or returns
nilafter timeout. -
#wait_for(event_type : T.class, timeout : Time::Span = 5.seconds, &) forall T
Registers a listener, runs the block, then waits for the matching event.
Instance Method Detail
Calls handlers for this exact event type in registration order. Handler exceptions propagate to the caller.
Registered handlers, grouped by exact event type. Prefer #on and #off
over modifying this registry directly.
Removes the handler identified by id for event_type. Does nothing if the handler is already gone.
Registers a handler and returns its UUID for removal with #off.
Subscriptions match the exact event type, not its subclasses.
id = bot.on(Rosegold::Event::HealthChanged) { |event| puts event.health }
bot.off(Rosegold::Event::HealthChanged, id)
Registers a handler for the next matching event and returns its UUID. Removes it before invoking the block, even if the block raises or emits again.
Waits for the next matching event, or returns nil after timeout.
Always removes its temporary listener before returning.
Registers a listener, runs the block, then waits for the matching event. Returns the event; raises on timeout. The timeout includes time in the block, but cannot interrupt it. The listener is removed even if the block raises.
The block triggers the action; it is not an event filter. Any event of the requested type can satisfy the wait, including an unrelated server message.