Class: PgPipeline::Runtime::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_pipeline/runtime/notification.rb

Instance Method Summary collapse

Constructor Details

#initializeNotification

Returns a new instance of Notification.



6
7
8
# File 'lib/pg_pipeline/runtime/notification.rb', line 6

def initialize
  @waiters = []
end

Instance Method Details

#signalObject



19
20
21
22
23
# File 'lib/pg_pipeline/runtime/notification.rb', line 19

def signal
  waiter = @waiters.shift or return false
  Runtime.wake_dequeued(waiter, self)
  true
end

#signal_allObject



25
26
27
28
29
# File 'lib/pg_pipeline/runtime/notification.rb', line 25

def signal_all
  pending, @waiters = @waiters, []
  pending.each { |waiter| Runtime.wake_dequeued(waiter, self) }
  nil
end

#wait(timeout = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/pg_pipeline/runtime/notification.rb', line 10

def wait(timeout = nil)
  Runtime.with_waiter(self, @waiters) do |waiter|
    Runtime.with_timeout(timeout) { Runtime.park(self, waiter) { false } }
    true
  rescue TimeoutError
    false
  end
end