Class: EventStoreClient::Broker

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/event_store_client/broker.rb

Instance Method Summary collapse

Methods included from Configuration

#config

Instance Method Details

#call(subscriptions, wait: false) ⇒ Object

Distributes known subscriptions to multiple threads

Parameters:

  • (EventStoreClient::Subscriptions)
  • wait (Boolean) (defaults to: false)

    (Optional) Controls if broker shold block main app process (useful for debugging)



12
13
14
15
16
17
18
19
20
21
# File 'lib/event_store_client/broker.rb', line 12

def call(subscriptions, wait: false)
  subscriptions.each do |subscription|
    threads << Thread.new do
      connection.listen(subscription, options: { interval: 1, count: 10 }) do |event|
        subscription.subscriber.call(event)
      end
    end
  end
  threads.each(&:join) if wait
end