jarib/childprocess — pull request #20 by thedjinn (2011-12-26 14:51:49+00:00)
Title: Add Process#wait to block and wait for a process

I was investigating a performance issue in the cucumber/aruba gem. Profiling turned out that most of the slowdown was caused by launching child processes and waiting for them to finish (with the poll_for_exit method). In my particular case the situation got out of hand because the polling interval was 0.1 seconds while the program that had to be run only took between five and ten milliseconds to execute.

I realized that most of the applications using poll_for_exit could benefit from having direct access to something like waitpid or an equivalent method, so I added the Process#wait method that blocks the current process until the child process is terminated.

The wait method has support for Unix, JRuby and Windows. It has been tested under MRI 1.8.7, 1.9.3 and JRuby 1.6.5. I assume the Windows version also works but do not have a development environment to test it on.

Also, here's an interesting side note: if you try and replace all occurrences of poll_for_exit in the specs to wait, everything still passes perfectly, and the specs even run a second faster.