Created
June 14, 2013 00:34
-
-
Save rickhull/5778575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'thread' | |
reader, writer = IO.pipe | |
t = Thread.new { | |
loop { | |
duration = rand(5) + 1 | |
sleep(duration) | |
writer.write "slept for #{duration} seconds" | |
} | |
} | |
puts "starting the select loop -- ctrl-c to quit" | |
puts "monitoring one side of an IO pipe, as well as STDIN" | |
puts "try typing in some input for STDIN..." | |
loop { | |
# blocks until there is something to process | |
# | |
read_ios, write_ios, error_ios = select([reader, $stdin]) | |
read_ios.each { |ri| | |
puts "#{ri} has something to read" | |
puts "readpartial(255): #{ri.readpartial(255)}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment