Created
June 6, 2012 06:32
-
-
Save ecavazos/2880276 to your computer and use it in GitHub Desktop.
A very basic celluloid example
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 Cat | |
| include Celluloid | |
| def initialize(name) | |
| @name = name | |
| end | |
| def speak | |
| 5.times do | |
| puts "#{@name} says meow!" | |
| sleep rand(5) #simulate a task that takes a few seconds to execute | |
| end | |
| terminate | |
| end | |
| end | |
| cats = Array.new(3) do |i| | |
| Cat.new "Kitty number #{i+1}" | |
| end | |
| cats.each(&:speak!) | |
| sleep 2 while cats.any?(&:alive?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment