Class: Estore::Commands::ReadForward
- Inherits:
-
Object
- Object
- Estore::Commands::ReadForward
- Includes:
- Command, Command::ReadStreamForward
- Defined in:
- lib/estore/commands/read_forward.rb
Instance Attribute Summary
Attributes included from Command
Instance Method Summary collapse
- #call ⇒ Object
- #handle(message) ⇒ Object
-
#initialize(connection, stream, from, batch_size = nil, &block) ⇒ ReadForward
constructor
A new instance of ReadForward.
Methods included from Command::ReadStreamForward
Methods included from Command
#decode, #promise, #register!, #reject!, #remove!, #write
Constructor Details
#initialize(connection, stream, from, batch_size = nil, &block) ⇒ ReadForward
Returns a new instance of ReadForward.
7 8 9 10 11 12 13 14 15 |
# File 'lib/estore/commands/read_forward.rb', line 7 def initialize(connection, stream, from, batch_size = nil, &block) super(connection) @stream = stream @from = from @batch_size = batch_size || 1000 @block = block @events = [] end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 |
# File 'lib/estore/commands/read_forward.rb', line 17 def call register! read(@stream, @from, @batch_size) promise end |
#handle(message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/estore/commands/read_forward.rb', line 23 def handle(, *) response = decode(ReadStreamEventsCompleted, ) events = Array(response.events) @from += events.size read(@stream, @from, @batch_size) unless response.is_end_of_stream @block ? @block.call(events) : @events.push(*events) if response.is_end_of_stream remove! promise.fulfill(@block ? nil : @events) end end |