Class: Microsandbox::AgentStream
- Inherits:
-
Object
- Object
- Microsandbox::AgentStream
- Includes:
- Enumerable
- Defined in:
- lib/microsandbox/agent.rb
Overview
An open raw agent stream, from Microsandbox::AgentClient#stream. Enumerable: iterate to consume AgentFrames until the stream ends (the terminal frame is delivered, then iteration stops). Mirrors the official SDKs’ ‘AgentStream`.
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
The protocol correlation id (pass to Microsandbox::AgentClient#send_frame).
Instance Method Summary collapse
-
#close ⇒ nil
Close the stream and release its handle.
- #each {|frame| ... } ⇒ self, Enumerator
-
#initialize(native, id, handle) ⇒ AgentStream
constructor
A new instance of AgentStream.
-
#recv ⇒ AgentFrame?
Pull the next frame, or nil at end-of-stream.
Constructor Details
#initialize(native, id, handle) ⇒ AgentStream
Returns a new instance of AgentStream.
47 48 49 50 51 |
# File 'lib/microsandbox/agent.rb', line 47 def initialize(native, id, handle) @native = native @id = id @handle = handle end |
Instance Attribute Details
#id ⇒ Integer (readonly)
Returns the protocol correlation id (pass to Microsandbox::AgentClient#send_frame).
45 46 47 |
# File 'lib/microsandbox/agent.rb', line 45 def id @id end |
Instance Method Details
#close ⇒ nil
Close the stream and release its handle. Idempotent.
73 74 75 76 |
# File 'lib/microsandbox/agent.rb', line 73 def close @native.stream_close(@handle) nil end |
#each {|frame| ... } ⇒ self, Enumerator
62 63 64 65 66 67 68 69 |
# File 'lib/microsandbox/agent.rb', line 62 def each return enum_for(:each) unless block_given? while (frame = recv) yield frame end self end |
#recv ⇒ AgentFrame?
Pull the next frame, or nil at end-of-stream.
55 56 57 58 |
# File 'lib/microsandbox/agent.rb', line 55 def recv frame = @native.stream_next(@handle) frame && AgentFrame.new(frame) end |