Class: ChatSDK::Streaming::Stream
- Inherits:
-
Object
- Object
- ChatSDK::Streaming::Stream
- Defined in:
- lib/chat_sdk/streaming/stream.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#thread_id ⇒ Object
readonly
Returns the value of attribute thread_id.
-
#update_interval ⇒ Object
readonly
Returns the value of attribute update_interval.
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
-
#initialize(adapter:, channel_id:, thread_id:, placeholder: nil, update_interval: 0.5) ⇒ Stream
constructor
A new instance of Stream.
- #run {|_self| ... } ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/chat_sdk/streaming/stream.rb', line 6 def adapter @adapter end |
#channel_id ⇒ Object (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_id ⇒ Object (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_interval ⇒ Object (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
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 |