Class: OpenLoam::EventStream::InProcessBroadcaster
- Inherits:
-
Object
- Object
- OpenLoam::EventStream::InProcessBroadcaster
- Defined in:
- lib/open_loam/event_stream.rb
Overview
The default fan-out: subscribe to OpenLoam::Events in THIS process and forward
the events deliverable to (tenant, actor) to a sink. A sink is anything
answering #call(sse_string) — the controller's is a Queue push.
Instance Method Summary collapse
-
#subscribe(tenant:, actor:, &sink) ⇒ Object
Returns an opaque handle to pass back to #unsubscribe.
- #unsubscribe(handle) ⇒ Object
Instance Method Details
#subscribe(tenant:, actor:, &sink) ⇒ Object
Returns an opaque handle to pass back to #unsubscribe.
67 68 69 70 71 72 73 |
# File 'lib/open_loam/event_stream.rb', line 67 def subscribe(tenant:, actor:, &sink) OpenLoam::Events.subscribe_all do |event_name, payload| next unless OpenLoam::EventStream.deliverable?(event_name, payload, tenant: tenant, actor: actor) sink.call(OpenLoam::EventStream.frame(event_name, payload)) end end |
#unsubscribe(handle) ⇒ Object
75 76 77 |
# File 'lib/open_loam/event_stream.rb', line 75 def unsubscribe(handle) ActiveSupport::Notifications.unsubscribe(handle) if handle end |