Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tijn/fork_pool
Imagine a pool containing a certain number of forks. These can be used to fork off code blocks.
https://github.com/tijn/fork_pool
Last synced: 6 days ago
JSON representation
Imagine a pool containing a certain number of forks. These can be used to fork off code blocks.
- Host: GitHub
- URL: https://github.com/tijn/fork_pool
- Owner: tijn
- Created: 2013-03-19T22:27:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-10-30T04:23:37.000Z (about 1 year ago)
- Last Synced: 2024-04-21T03:59:45.129Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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
-----```ruby
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!
endpool.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.