Class: MailSandbox::Subscriber
- Inherits:
-
Object
- Object
- MailSandbox::Subscriber
- Defined in:
- lib/mail_sandbox/subscriber.rb
Instance Method Summary collapse
- #mutex ⇒ Object
- #notify(message) ⇒ Object
- #observers ⇒ Object
- #subscribe(observer) ⇒ Object
- #unsubscribe(observer) ⇒ Object
Instance Method Details
#mutex ⇒ Object
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() observers.each_value do |observer| thread = Thread.new do mutex.synchronize do observer.update() end end thread.abort_on_exception = true #thread.run end end |
#observers ⇒ Object
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 |