Skip to content

Instantly share code, notes, and snippets.

@asterite
Created February 1, 2015 02:51
Show Gist options
  • Save asterite/820e16be4bbb7d7c3c65 to your computer and use it in GitHub Desktop.
Save asterite/820e16be4bbb7d7c3c65 to your computer and use it in GitHub Desktop.
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