Class: SimpleAcp::Client::SSEStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/simple_acp/client/sse.rb

Overview

Enumerable wrapper for streaming SSE responses.

Reads from an HTTP response body, parses SSE events, and converts them to ACP event objects.

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SSEStream

Create a new SSE stream reader.

Parameters:

  • response (Net::HTTPResponse) —

    the HTTP response with SSE body



110
111
112
113
# File 'lib/simple_acp/client/sse.rb', line 110

def initialize(response)
  @response = response
  @parser = SSEParser.new
end

Instance Method Details

#each {|Models::Event| ... } ⇒ Enumerator

Iterate over ACP events from the stream.

Yields:

Returns:

  • (Enumerator) —

    if no block given



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/simple_acp/client/sse.rb', line 119

def each
  return enum_for(:each) unless block_given?

  @response.body.each do |chunk|
    @parser.feed(chunk)
    @parser.each_event do |raw_event|
      event = parse_acp_event(raw_event)
      yield event if event
    end
  end
end