Module: OCI::SSEReader

Defined in:
lib/oci/sse_reader.rb

Overview

Used to read the server sent events

Class Method Summary collapse

Class Method Details

.read_streamObject

Read the stream using event_stream_parser library



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/oci/sse_reader.rb', line 8

def self.read_stream
  proc { |response|
    require 'event_stream_parser'
    parser = EventStreamParser::Parser.new
    response.lines do |chunk|
      parser.feed(chunk) do |_type, data, _id, _reconnection_time|
        parsed = JSON.parse(data)
        print parsed['text']
      end
    end
  }
end