Class: Async::IO::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/async/io/notification.rb

Overview

A cross-reactor/process notification pipe.

Instance Method Summary collapse

Constructor Details

#initializeNotification

Returns a new instance of Notification.



29
30
31
32
33
34
35
# 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

Instance Method Details

#closeObject



37
38
39
40
# File 'lib/async/io/notification.rb', line 37

def close
	@input.close
	@output.close
end

#signalvoid

This method returns an undefined value.

Signal to a given task that it should resume operations.



54
55
56
57
58
59
# File 'lib/async/io/notification.rb', line 54

def signal
	wrapper = Async::IO::Generic.new(@output)
	wrapper.write(".")
ensure
	wrapper.reactor = nil
end

#waitObject

Wait for signal to be called.

Returns:

  • (Object)


44
45
46
47
48
49
50
# 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