Class: Microsandbox::AgentStream
- Inherits:
-
Object
- Object
- Microsandbox::AgentStream
- Includes:
- Enumerable
- Defined in:
- lib/microsandbox/agent.rb
Overview
Single-pass, forward-only, single-consumer. each drains a
one-shot native channel — not rewindable, iterate once from a single
thread; a second pass or a post-drain combinator yields nothing.
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.
51 52 53 54 55 |
# File 'lib/microsandbox/agent.rb', line 51 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).
49 50 51 |
# File 'lib/microsandbox/agent.rb', line 49 def id @id end |
Instance Method Details
#close ⇒ nil
Close the stream and release its handle. Idempotent.
77 78 79 80 |
# File 'lib/microsandbox/agent.rb', line 77 def close @native.stream_close(@handle) nil end |
#each {|frame| ... } ⇒ self, Enumerator
66 67 68 69 70 71 72 73 |
# File 'lib/microsandbox/agent.rb', line 66 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.
59 60 61 62 |
# File 'lib/microsandbox/agent.rb', line 59 def recv frame = @native.stream_next(@handle) frame && AgentFrame.new(frame) end |