Created
October 18, 2013 16:05
-
-
Save jmazzi/7043795 to your computer and use it in GitHub Desktop.
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 'monitor' | |
require 'celluloid' | |
class BossArray < Array | |
include MonitorMixin | |
def initialize(*args) | |
super(*args) | |
end | |
alias :old_shift :shift | |
alias :old_unshift :unshift | |
def shift(n=1) | |
self.synchronize do | |
self.old_shift(n) | |
end | |
end | |
def unshift(item) | |
self.synchronize do | |
self.old_unshift(item) | |
end | |
end | |
end | |
class What | |
include Celluloid | |
def append(array, item) | |
array.unshift item | |
end | |
end | |
array = BossArray.new(['test']) | |
wtfs = What.pool(size: 100) | |
results = 500.times.map do |i| | |
wtfs.future.append(array, i) | |
end | |
results.map(&:value) | |
puts array.size |
Author
jmazzi
commented
Oct 18, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment