Class: PostOffice
Instance Method Summary collapse
- #deliver(to, msg) ⇒ Object
-
#initialize ⇒ PostOffice
constructor
A new instance of PostOffice.
- #read(box) ⇒ Object
Constructor Details
#initialize ⇒ PostOffice
Returns a new instance of PostOffice.
10 11 12 13 |
# File 'lib/pregel.rb', line 10 def initialize @mailboxes = Hash.new @mutex = Mutex.new end |
Instance Method Details
#deliver(to, msg) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/pregel.rb', line 15 def deliver(to, msg) @mutex.synchronize do if @mailboxes[to] @mailboxes[to].push msg else @mailboxes[to] = [msg] end end end |
#read(box) ⇒ Object
25 26 27 28 29 |
# File 'lib/pregel.rb', line 25 def read(box) @mutex.synchronize do @mailboxes.delete(box) || [] end end |