Created
September 2, 2013 19:28
-
-
Save clausd/6416463 to your computer and use it in GitHub Desktop.
Nonblocking writes, blocking reads
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
`mkfifo fifotest` | |
Process.fork do | |
puts "We're going to write a message to a process who will pick it up later" | |
nonblocking = open('fifotest', 'w+') | |
nonblocking.puts "A message for you, Rudy\r\n" | |
nonblocking.flush | |
nonblocking.close | |
puts "Done writing" | |
end | |
puts "Going to read" | |
blocking = open('fifotest', 'r+') | |
puts blocking.readline | |
puts "Going to block, since nothing is there" | |
puts blocking.readline | |
blocking.close | |
# echo go away > fifotest | |
# terminates the script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment