Skip to content

Instantly share code, notes, and snippets.

@jmazzi
Created October 18, 2013 16:05
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 jmazzi/7043795 to your computer and use it in GitHub Desktop.
Save jmazzi/7043795 to your computer and use it in GitHub Desktop.
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
@jmazzi
Copy link
Author

jmazzi commented Oct 18, 2013

501
D, [2013-10-18T12:05:16.868703 #3145] DEBUG -- : Terminating 101 actors...
W, [2013-10-18T12:05:16.878673 #3145]  WARN -- : Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:callwait

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment