Sha256: 60e3fb24e7e669890406c0ecdb4d9eb59d99f72a7852d1e1dad4e7686afcf156

Contents?: true

Size: 569 Bytes

Versions: 4

Compression:

Stored size: 569 Bytes

Contents

module MailSandbox
  class Subscriber

    def subscribe(observer)
      observers[observer] ||= observer
    end

    def unsubscribe(observer)
      observers.delete(observer)
    end

    def notify(message)
      observers.each_value do |observer|

        thread = Thread.new do
          mutex.synchronize do
            observer.update(message)
          end
        end

        thread.abort_on_exception = true
        #thread.run
      end
    end

    def observers
      @observers ||= {}
    end

    def mutex
      @mutex ||= Mutex.new
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mail_sandbox-0.1.3 lib/mail_sandbox/subscriber.rb
mail_sandbox-0.1.2 lib/mail_sandbox/subscriber.rb
mail_sandbox-0.1.1 lib/mail_sandbox/subscriber.rb
mail_sandbox-0.1.0 lib/mail_sandbox/subscriber.rb