Class: Chutzen::Demux
- Inherits:
-
Object
- Object
- Chutzen::Demux
- Defined in:
- lib/chutzen/demux.rb
Overview
Reads from one stream and writes to a set of other streams.
demux = Demux.new(stdin, [file, file, socket, stdout])
until demux.done?
demux.tick
end
Constant Summary collapse
- BUFFER_SIZE =
1024
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(input, *output, select_timeout: nil) ⇒ Demux
constructor
A new instance of Demux.
- #tick ⇒ Object
Constructor Details
#initialize(input, *output, select_timeout: nil) ⇒ Demux
Returns a new instance of Demux.
13 14 15 16 17 18 |
# File 'lib/chutzen/demux.rb', line 13 def initialize(input, *output, select_timeout: nil) @input = input @output = output @select_timeout = select_timeout @done = false end |
Instance Method Details
#done? ⇒ Boolean
20 21 22 |
# File 'lib/chutzen/demux.rb', line 20 def done? @done end |
#tick ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chutzen/demux.rb', line 24 def tick readable = IO.select([@input], nil, nil, @select_timeout) return unless readable buffer = readable.first.first.read_nonblock(BUFFER_SIZE) @done = buffer.nil? @output.each { |stream| stream.write(buffer) } rescue IOError @done = true end |