Class: ChatSDK::Streaming::Stream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:, channel_id:, thread_id:, placeholder: nil, update_interval: 0.5) ⇒ Stream

Returns a new instance of Stream.



8
9
10
11
12
13
14
15
16
17
# File 'lib/chat_sdk/streaming/stream.rb', line 8

def initialize(adapter:, channel_id:, thread_id:, placeholder: nil, update_interval: 0.5)
  @adapter = adapter
  @channel_id = channel_id
  @thread_id = thread_id
  @placeholder = placeholder
  @update_interval = update_interval
  @buffer = +""
  @message_id = nil
  @last_flush_at = nil
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



6
7
8
# File 'lib/chat_sdk/streaming/stream.rb', line 6

def adapter
  @adapter
end

#channel_idObject (readonly)

Returns the value of attribute channel_id.



6
7
8
# File 'lib/chat_sdk/streaming/stream.rb', line 6

def channel_id
  @channel_id
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



6
7
8
# File 'lib/chat_sdk/streaming/stream.rb', line 6

def thread_id
  @thread_id
end

#update_intervalObject (readonly)

Returns the value of attribute update_interval.



6
7
8
# File 'lib/chat_sdk/streaming/stream.rb', line 6

def update_interval
  @update_interval
end

Instance Method Details

#<<(chunk) ⇒ Object



19
20
21
22
23
# File 'lib/chat_sdk/streaming/stream.rb', line 19

def <<(chunk)
  @buffer << chunk.to_s
  maybe_flush
  self
end

#run {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



25
26
27
28
29
# File 'lib/chat_sdk/streaming/stream.rb', line 25

def run(&block)
  post_placeholder if @placeholder
  yield self
  flush
end