class Async::IO::Notification

A cross-reactor/process notification pipe.

Public Class Methods

new() click to toggle source
# File lib/async/io/notification.rb, line 29
def initialize
        pipe = ::IO.pipe
        
        # We could call wait and signal from different reactors/threads/processes, so we don't create wrappers here, because they are not thread safe by design.
        @input = pipe.first
        @output = pipe.last
end

Public Instance Methods

close() click to toggle source
# File lib/async/io/notification.rb, line 37
def close
        @input.close
        @output.close
end
signal() click to toggle source

Signal to a given task that it should resume operations. @return [void]

# File lib/async/io/notification.rb, line 54
def signal
        wrapper = Async::IO::Generic.new(@output)
        wrapper.write(".")
ensure
        wrapper.reactor = nil
end
wait() click to toggle source

Wait for signal to be called. @return [Object]

# File lib/async/io/notification.rb, line 44
def wait
        wrapper = Async::IO::Generic.new(@input)
        wrapper.read(1)
ensure
        # Remove the wrapper from the reactor.
        wrapper.reactor = nil
end