Class: Microsandbox::LogStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/microsandbox/streams.rb

Overview

A live stream of LogEntrys, returned by Sandbox#log_stream. Enumerable: iterate to consume entries as they are appended. With ‘follow: true` the iteration blocks for new entries until the sandbox stops; otherwise it ends once the historical log is drained.

Examples:

sb.log_stream(follow: true).each { |entry| print entry.text }

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ LogStream

Returns a new instance of LogStream.



14
15
16
# File 'lib/microsandbox/streams.rb', line 14

def initialize(native)
  @native = native
end

Instance Method Details

#each {|entry| ... } ⇒ self, Enumerator

Yield Parameters:

Returns:

  • (self, Enumerator)


20
21
22
23
24
25
26
27
# File 'lib/microsandbox/streams.rb', line 20

def each
  return enum_for(:each) unless block_given?

  while (entry = @native.recv)
    yield LogEntry.new(entry)
  end
  self
end