Created
February 1, 2015 02:51
-
-
Save asterite/820e16be4bbb7d7c3c65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def with_pipe | |
read, write = IO.pipe | |
yield read, write | |
ensure | |
read.close if read rescue nil | |
write.close if write rescue nil | |
end | |
with_pipe do |read, write| | |
thread = Thread.new do | |
puts IO.select(nil, nil, [write]).include?(write) | |
end | |
write.close | |
read.close | |
thread.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment