Class: Tribe::Mailbox
- Inherits:
-
Object
- Object
- Tribe::Mailbox
- Defined in:
- lib/tribe/mailbox.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Mailbox
constructor
A new instance of Mailbox.
- #push(event, &block) ⇒ Object
- #release(&block) ⇒ Object
- #shift ⇒ Object
- #synchronize(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mailbox
Returns a new instance of Mailbox.
3 4 5 6 |
# File 'lib/tribe/mailbox.rb', line 3 def initialize( = {}) = [] @mutex = Mutex.new end |
Instance Method Details
#push(event, &block) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/tribe/mailbox.rb', line 8 def push(event, &block) @mutex.synchronize do .push(event) block.call unless @current_thread end return nil end |
#release(&block) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/tribe/mailbox.rb', line 27 def release(&block) @mutex.synchronize do @current_thread = nil block.call if block && .length > 0 end return nil end |
#shift ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tribe/mailbox.rb', line 17 def shift @mutex.synchronize do return nil if @current_thread && @current_thread != Thread.current @current_thread = Thread.current unless @current_thread return .shift end end |
#synchronize(&block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tribe/mailbox.rb', line 36 def synchronize(&block) @mutex.synchronize do block.call end return nil end |