class Async::IO::Trap
A cross-reactor/process notification pipe.
def async(parent: Task.current, **options, &block)
def async(parent: Task.current, **options, &block) parent.async(**options) do |task| self.wait(task: task, &block) end end
def default!
def default! Signal.trap(@name, :DEFAULT) end
def ignore!
def ignore! Signal.trap(@name, :IGNORE) end
def initialize(name)
def initialize(name) @name = name @notifications = [] @installed = false @mutex = Mutex.new end
def install!
-
(Boolean)- whether the trap was installed or not. If the trap was already installed, returns nil.
def install! return if @installed @mutex.synchronize do return if @installed Signal.trap(@name, &self.method(:trigger)) @installed = true end return true end
def to_s
def to_s "\#<#{self.class} #{@name}>" end
def trigger(signal_number = nil)
-
(void)-
def trigger(signal_number = nil) @notifications.each(&:signal) end
def wait(task: Task.current, &block)
- Yield: - the current task.
def wait(task: Task.current, &block) task.annotate("waiting for signal #{@name}") notification = Notification.new @notifications << notification if block_given? while true notification.wait yield task end else notification.wait end ensure if notification notification.close @notifications.delete(notification) end end