Class: Rjq::Runtime::ResultStream
- Inherits:
-
Object
- Object
- Rjq::Runtime::ResultStream
- Includes:
- Enumerable
- Defined in:
- lib/rjq/runtime.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(on_close: nil, &producer) ⇒ ResultStream
constructor
A new instance of ResultStream.
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
#close ⇒ Object
139 140 141 142 143 144 |
# File 'lib/rjq/runtime.rb', line 139 def close return if @closed @closed = true @on_close&.call end |
#each ⇒ Object
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 |