Class: Rjq::Runtime::ResultStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rjq/runtime.rb

Instance Method Summary collapse

Constructor Details

#initialize(on_close: nil, &producer) ⇒ ResultStream

Returns a new instance of ResultStream.



123
124
125
126
127
# File 'lib/rjq/runtime.rb', line 123

def initialize(on_close: nil, &producer)
  @producer = producer
  @on_close = on_close
  @closed = false
end

Instance Method Details

#closeObject



139
140
141
142
143
144
# File 'lib/rjq/runtime.rb', line 139

def close
  return if @closed

  @closed = true
  @on_close&.call
end

#eachObject



129
130
131
132
133
134
135
136
137
# File 'lib/rjq/runtime.rb', line 129

def each
  return enum_for(:each) unless block_given?

  begin
    @producer.call(->(value) { yield value })
  ensure
    close
  end
end