Class: Braintrust::Server::SSEBody

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/server/sse.rb

Overview

Rack-compatible response body that streams SSE events via ‘each`.

Works with Puma (immediate writes), Passenger, and rack-test. WEBrick buffers the entire body and is unsuitable for SSE.

Falcon buffers ‘each`-based bodies as Enumerable; use SSEStreamBody instead.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SSEBody

Returns a new instance of SSEBody.



12
13
14
# File 'lib/braintrust/server/sse.rb', line 12

def initialize(&block)
  @block = block
end

Instance Method Details

#eachObject



16
17
18
19
# File 'lib/braintrust/server/sse.rb', line 16

def each
  writer = SSEWriter.new { |chunk| yield chunk }
  @block.call(writer)
end