8000 GitHub - tijn/fork_pool: Imagine a pool containing a certain number of forks. These can be used to fork off code blocks.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tijn/fork_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fork_pool

A pool that contains a number of forks. The pool can use this cutlery to fork off code blocks.

What?

Yeah, so, I was just reading about processes and forking in Ruby and then I decided I would learn more by actually writing a small library. This is it.

Usage

pool = ForkPool.new(4) # max 4 childs processes at a time

# ForkPool#spork forks off a block of code and also spoons up finished processes.
pool.spork do
  do_something_impressive_that_needs_multiple_processors!
end

pool.wait # optional, you may opt to let the parent process die before its childs. Your choice.

puts "done!"

Known issues

ForkPool#wait will wait for ANY child process to die even if it was started by another pool.

Really, if you try to use this code with multiple pools (that have processes running at the same time) you are asking for trouble.

About

Imagine a pool containing a certain number of forks. These can be used to fork off code blocks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

0