Skip to content

Instantly share code, notes, and snippets.

@ecavazos
Created June 6, 2012 06:32
Show Gist options
  • Save ecavazos/2880276 to your computer and use it in GitHub Desktop.
Save ecavazos/2880276 to your computer and use it in GitHub Desktop.
A very basic celluloid example
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