Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created June 11, 2012 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/2912970 to your computer and use it in GitHub Desktop.
Save havenwood/2912970 to your computer and use it in GitHub Desktop.
concurrent array making with Celluloid
require 'celluloid'
class ArrayMaker
include Celluloid
attr_reader :content
def initialize
@content = []
end
def add_five
1.upto 5 do |n|
@content << n
sleep 5
end
end
end
numbers = ArrayMaker.new
numbers.content
# => []
numbers.add_five!
# => nil
numbers.content
#=> [1]
sleep 10
numbers.content
# => [1,2,3]
sleep 10
numbers.content
# => [1,2,3,4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment