Class: Reacto::Operations::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/reacto/operations/buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(count: nil, delay: nil) ⇒ Buffer

Returns a new instance of Buffer.



7
8
9
10
11
# File 'lib/reacto/operations/buffer.rb', line 7

def initialize(count: nil, delay: nil)
  @count = count
  @delay = delay
  @buffer = []
end

Instance Method Details

#call(tracker) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/reacto/operations/buffer.rb', line 13

def call(tracker)
  close = lambda do
    finish(tracker)
    tracker.on_close
  end
  error = lambda do |e|
    finish(tracker)
    tracker.on_error(e)
  end
  value = if !@count.nil? && @delay.nil?
            count_buffer_behaviour(tracker)
          elsif @count.nil? && !@delay.nil?
            delay_buffer_behaviour(tracker)
          elsif @count && @delay
            count_and_delay_buffer_behaviour(tracker)
          else
            tracker.method(:on_value)
          end

  Subscriptions::OperationSubscription.new(
    tracker, value: value, close: close, error: error
  )
end