Created
June 11, 2012 21:51
-
-
Save havenwood/2912970 to your computer and use it in GitHub Desktop.
concurrent array making with Celluloid
This file contains 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 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