lib/finite_machine/subscribers.rb in finite_machine-0.2.0 vs lib/finite_machine/subscribers.rb in finite_machine-0.3.0

- old
+ new

@@ -1,17 +1,20 @@ # encoding: utf-8 +require 'monitor' + module FiniteMachine # A class responsibile for storage of event subscribers class Subscribers include Enumerable + include MonitorMixin def initialize(machine) + super() @machine = machine @subscribers = [] - @mutex = Mutex.new end def each(&block) @subscribers.each(&block) end @@ -27,10 +30,10 @@ def subscribe(*observers) observers.each { |observer| @subscribers << observer } end def visit(event) - each { |subscriber| event.notify subscriber } + each { |subscriber| synchronize { event.notify subscriber } } end def reset @subscribers.clear self