Class: Async::Background::Runtime::Notification
- Inherits:
-
Object
- Object
- Async::Background::Runtime::Notification
- Defined in:
- lib/async/background/runtime/notification.rb
Instance Method Summary collapse
-
#initialize ⇒ Notification
constructor
A new instance of Notification.
- #signal ⇒ Object
- #signal_all ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #wait_until(deadline = nil) ⇒ Object
- #waiting ⇒ Object
Constructor Details
#initialize ⇒ Notification
Returns a new instance of Notification.
7 8 9 |
# File 'lib/async/background/runtime/notification.rb', line 7 def initialize @waiters = [] end |
Instance Method Details
#signal ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/async/background/runtime/notification.rb', line 23 def signal while (waiter = @waiters.shift) return true if Runtime.wake_dequeued(waiter, self) end false end |
#signal_all ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/async/background/runtime/notification.rb', line 31 def signal_all return nil if @waiters.empty? pending, @waiters = @waiters, [] pending.each { |waiter| Runtime.wake_dequeued(waiter, self) } nil end |
#wait(timeout = nil) ⇒ Object
13 14 15 |
# File 'lib/async/background/runtime/notification.rb', line 13 def wait(timeout = nil) wait_until(Runtime.deadline_for(timeout)) end |
#wait_until(deadline = nil) ⇒ Object
17 18 19 20 21 |
# File 'lib/async/background/runtime/notification.rb', line 17 def wait_until(deadline = nil) Runtime.with_waiter(self, @waiters) do |waiter| Runtime.park(self, waiter, deadline) { false } end end |
#waiting ⇒ Object
11 |
# File 'lib/async/background/runtime/notification.rb', line 11 def waiting = @waiters.size |