Class: Microsandbox::ExecHandle
- Inherits:
-
Object
- Object
- Microsandbox::ExecHandle
- Includes:
- Enumerable
- Defined in:
- lib/microsandbox/exec_handle.rb
Overview
A live, streaming command execution, returned by Sandbox#exec_stream and Sandbox#shell_stream.
Iterate it (it is Enumerable) to consume ExecEvents as they arrive, or call #collect to drain it into an ExecOutput.
Instance Method Summary collapse
-
#collect ⇒ ExecOutput
Drain the stream and collect all output.
-
#each {|event| ... } ⇒ self, Enumerator
Yield each ExecEvent until the stream ends.
-
#id ⇒ String
The correlation id for this execution.
-
#initialize(native) ⇒ ExecHandle
constructor
A new instance of ExecHandle.
-
#kill ⇒ nil
Kill the running process (SIGKILL).
-
#resize(rows, cols) ⇒ nil
Resize the pseudo-terminal (only meaningful when started with tty: true).
-
#signal(sig) ⇒ nil
Send a signal (integer) to the running process.
-
#stdin ⇒ ExecStdin?
The stdin writer, or nil if stdin was not piped.
-
#wait ⇒ ExitStatus
Block until the process exits.
Constructor Details
#initialize(native) ⇒ ExecHandle
Returns a new instance of ExecHandle.
97 98 99 |
# File 'lib/microsandbox/exec_handle.rb', line 97 def initialize(native) @native = native end |
Instance Method Details
#collect ⇒ ExecOutput
Drain the stream and collect all output.
127 128 129 |
# File 'lib/microsandbox/exec_handle.rb', line 127 def collect ExecOutput.new(@native.collect) end |
#each {|event| ... } ⇒ self, Enumerator
Yield each Microsandbox::ExecEvent until the stream ends. Returns an Enumerator when called without a block.
110 111 112 113 114 115 116 117 |
# File 'lib/microsandbox/exec_handle.rb', line 110 def each return enum_for(:each) unless block_given? while (event = @native.recv) yield ExecEvent.new(event) end self end |
#id ⇒ String
Returns the correlation id for this execution.
102 103 104 |
# File 'lib/microsandbox/exec_handle.rb', line 102 def id @native.id end |
#kill ⇒ nil
Kill the running process (SIGKILL).
140 141 142 143 |
# File 'lib/microsandbox/exec_handle.rb', line 140 def kill @native.kill nil end |
#resize(rows, cols) ⇒ nil
Resize the pseudo-terminal (only meaningful when started with tty: true).
147 148 149 150 |
# File 'lib/microsandbox/exec_handle.rb', line 147 def resize(rows, cols) @native.resize(Integer(rows), Integer(cols)) nil end |
#signal(sig) ⇒ nil
Send a signal (integer) to the running process.
133 134 135 136 |
# File 'lib/microsandbox/exec_handle.rb', line 133 def signal(sig) @native.signal(Integer(sig)) nil end |
#stdin ⇒ ExecStdin?
The stdin writer, or nil if stdin was not piped. Returned only once.
154 155 156 157 158 159 |
# File 'lib/microsandbox/exec_handle.rb', line 154 def stdin return @stdin if defined?(@stdin) native_sink = @native.take_stdin @stdin = native_sink && ExecStdin.new(native_sink) end |
#wait ⇒ ExitStatus
Block until the process exits.
121 122 123 |
# File 'lib/microsandbox/exec_handle.rb', line 121 def wait ExitStatus.new(@native.wait) end |