Class: Eventus::Dispatchers::Synchronous

Inherits:
Object
  • Object
show all
Defined in:
lib/eventus/dispatchers/synchronous.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(persistence, &block) ⇒ Synchronous

Returns a new instance of Synchronous.



6
7
8
9
# File 'lib/eventus/dispatchers/synchronous.rb', line 6

def initialize(persistence, &block)
  @persistence = persistence
  @action = block || lambda {}
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/eventus/dispatchers/synchronous.rb', line 4

def action
  @action
end

Instance Method Details

#dispatch(events) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/eventus/dispatchers/synchronous.rb', line 11

def dispatch(events)
  Eventus.logger.info "Dispatching #{events.length} events"
  events.each do |e|
    @action.call(e)
    @persistence.mark_dispatched e
  end
end