Created
June 7, 2012 17:45
-
-
Save bensie/2890315 to your computer and use it in GitHub Desktop.
playing with celluloid
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
| require "celluloid" | |
| class Runner | |
| include Celluloid | |
| def initialize | |
| if block_given? | |
| puts "starting instance run" | |
| yield self | |
| puts "finished instance run" | |
| end | |
| end | |
| def run | |
| (1..10).map do |i| | |
| run_pool.future(:do_stuff, i) | |
| end.map(&:value) | |
| end | |
| def do_stuff(i) | |
| puts "running on #{i}" | |
| puts "finishing on #{i}" | |
| end | |
| private | |
| def run_pool | |
| @run_pool ||= Runner.pool(size: 2) | |
| end | |
| end | |
| puts "Let's get started" | |
| Runner.new do |r| | |
| r.run | |
| end | |
| puts "Done with everything, move on" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment