Class: Nucleus::StreamCallback

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/nucleus/core/common/stream_callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #log, logger_for

Constructor Details

#initialize(stream) ⇒ StreamCallback

Returns a new instance of StreamCallback.



7
8
9
10
# File 'lib/nucleus/core/common/stream_callback.rb', line 7

def initialize(stream)
  @stream = stream
  @closed = false
end

Instance Attribute Details

#closedObject

Returns the value of attribute closed.



5
6
7
# File 'lib/nucleus/core/common/stream_callback.rb', line 5

def closed
  @closed
end

Instance Method Details

#closevoid

This method returns an undefined value.

Close the stream



21
22
23
24
25
# File 'lib/nucleus/core/common/stream_callback.rb', line 21

def close
  log.debug 'Close API stream, invoked by adapter callback'
  # close API stream of the Rack server unless it was already closed
  @stream.close unless @closed
end

#send_message(message) ⇒ Object

Send a message via the stream to the client

Parameters:

  • message (String)

    content to send to the client



14
15
16
17
# File 'lib/nucleus/core/common/stream_callback.rb', line 14

def send_message(message)
  log.debug "New streamed message part: #{message}"
  @stream.chunk message
end