Class: Octoryn::TextStream
- Inherits:
-
Object
- Object
- Octoryn::TextStream
- Includes:
- Enumerable
- Defined in:
- lib/octoryn/text_stream.rb
Overview
A lazy, cancellable, replayable stream of normalized Octoryn events.
Instance Method Summary collapse
- #cancel ⇒ Object
- #each ⇒ Object
-
#initialize(governance: nil, &producer) ⇒ TextStream
constructor
A new instance of TextStream.
- #result ⇒ Object
Constructor Details
#initialize(governance: nil, &producer) ⇒ TextStream
Returns a new instance of TextStream.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/octoryn/text_stream.rb', line 8 def initialize(governance: nil, &producer) @governance = governance @producer = producer @events = [] @source = nil @complete = false @result = nil @error = nil @cancelled = false end |
Instance Method Details
#cancel ⇒ Object
36 37 38 39 40 |
# File 'lib/octoryn/text_stream.rb', line 36 def cancel @cancelled = true @error = Error.new('Octoryn stream cancelled') @complete = true end |
#each ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/octoryn/text_stream.rb', line 19 def each(&) return enum_for(:each) unless block_given? @events.each(&) return finish_replay if @complete consume_events(&) raise @error if @error end |
#result ⇒ Object
29 30 31 32 33 34 |
# File 'lib/octoryn/text_stream.rb', line 29 def result each { nil } unless @complete raise @error if @error @result || raise(Error, 'Octoryn stream has no final result') end |