class Process::Daemon::Notification
This is a one shot cross-process notification mechanism using pipes. It can also be used in the same process if required, e.g. the self-pipe trick.
Public Class Methods
new()
click to toggle source
# File lib/process/daemon/notification.rb, line 25 def initialize @output, @input = IO.pipe @signalled = false end
Public Instance Methods
signal()
click to toggle source
Signal the notification.
# File lib/process/daemon/notification.rb, line 32 def signal @signalled = true @input.puts end
signalled?()
click to toggle source
Was this notification signalled?
# File lib/process/daemon/notification.rb, line 39 def signalled? @signalled end
wait(timeout: nil)
click to toggle source
Wait/block until a signal is received. Optional timeout. @param timeout [Integer] the time to wait in seconds.
# File lib/process/daemon/notification.rb, line 45 def wait(timeout: nil) if timeout read_ready, _, _ = IO.select([@output], [], [], timeout) return false unless read_ready and read_ready.any? end @signalled or @output.read(1) # Just in case that this was split across multiple processes. @signalled = true end