Created
September 11, 2010 02:06
-
-
Save elight/574685 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 fork_tourist | |
fork do | |
# we're in the child | |
# run your tour | |
end | |
end | |
number_of_tours = 20 | |
pipes = [] | |
number_of_tours.times do |idx| | |
pipe.read, pipe.write = IO.pipe | |
pipes << [idx, pipe.read, pipe.write] | |
end | |
pipes.each do |pipe| | |
fork_tourist | |
end | |
MAX_LEN = 1024 | |
# we're in the parent | |
while true | |
pipes.each do |id, pipe_read, _| | |
result = read_pipe.read_nonblock(MAX_LEN) | |
case result | |
... | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment