Class: MailSandbox::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_sandbox/subscriber.rb

Instance Method Summary collapse

Instance Method Details

#mutexObject



30
31
32
# File 'lib/mail_sandbox/subscriber.rb', line 30

def mutex
  @mutex ||= Mutex.new
end

#notify(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mail_sandbox/subscriber.rb', line 12

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

#observersObject



26
27
28
# File 'lib/mail_sandbox/subscriber.rb', line 26

def observers
  @observers ||= {}
end

#subscribe(observer) ⇒ Object



4
5
6
# File 'lib/mail_sandbox/subscriber.rb', line 4

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

#unsubscribe(observer) ⇒ Object



8
9
10
# File 'lib/mail_sandbox/subscriber.rb', line 8

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