Class: Synapse::EventSourcing::CountingEventStream

Inherits:
Domain::DomainEventStream show all
Extended by:
Forwardable
Defined in:
lib/synapse/event_sourcing/snapshot/count_stream.rb

Overview

Event stream decorator that simply counts each event that is retrieved from a delegate stream

Direct Known Subclasses

TriggeringEventStream

Instance Method Summary collapse

Methods inherited from Domain::DomainEventStream

#each, #end?, #peek, #to_a

Constructor Details

#initialize(delegate, counter) ⇒ undefined

Parameters:

  • delegate (DomainEventStream)
  • counter (Atomic)


10
11
12
13
# File 'lib/synapse/event_sourcing/snapshot/count_stream.rb', line 10

def initialize(delegate, counter)
  @delegate = delegate
  @counter = counter
end

Instance Method Details

#next_eventDomainEventMessage

Returns:

  • (DomainEventMessage)


16
17
18
19
20
21
22
23
24
# File 'lib/synapse/event_sourcing/snapshot/count_stream.rb', line 16

def next_event
  next_event = @delegate.next_event

  @counter.update do |value|
    value = value.next
  end

  next_event
end