mardi 5 mai 2015

Return from multiple ruby forks

I have the following code

read, write = IO.pipe
count = {}
ARGV.each do |filename|
    fork do
        read.close
        write.write Marshal.dump(do_stuff(filename))
        write.close
    end
end
write.close
count = Marshal.load(read.read)
read.close
Process.waitall

printf(count)

which works for one fork but I obviously want to achieve concurrency so I'd need to get the count hash from all the forks. However I've so far only been able to retrieve one hash from either of the forks. How can I return all of them?

Aucun commentaire:

Enregistrer un commentaire