Class: RubyAPI::SSEStream

Inherits:
Object
  • Object
show all
Defined in:
lib/fastrb/streaming.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSSEStream

Returns a new instance of SSEStream.



37
38
39
40
41
# File 'lib/fastrb/streaming.rb', line 37

def initialize
  @body = StreamingBody.new
  @sse = SSE.new(@body)
  @closed = false
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



35
36
37
# File 'lib/fastrb/streaming.rb', line 35

def body
  @body
end

Instance Method Details

#closeObject



48
49
50
51
52
# File 'lib/fastrb/streaming.rb', line 48

def close
  @closed = true
  @sse.close
  @body.close
end

#closed?Boolean

Returns:



54
55
56
# File 'lib/fastrb/streaming.rb', line 54

def closed?
  @closed
end

#send_event(event:, data:, id: nil) ⇒ Object



43
44
45
46
# File 'lib/fastrb/streaming.rb', line 43

def send_event(event:, data:, id: nil)
  return if @closed
  @sse.send(event: event, data: data, id: id)
end