Class: Async::Worker::Notification
- Inherits:
-
Object
- Object
- Async::Worker::Notification
- Defined in:
- lib/async/worker/notification.rb
Overview
A cross-thread notification pipe.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Notification
constructor
A new instance of Notification.
-
#signal ⇒ void
Signal to a given task that it should resume operations.
-
#wait ⇒ Object
Wait for signal to be called.
Constructor Details
#initialize ⇒ Notification
Returns a new instance of Notification.
29 30 31 32 33 34 35 |
# File 'lib/async/worker/notification.rb', line 29 def initialize pipe = ::IO.pipe @mutex = Mutex.new @input = pipe.first @output = pipe.last end |
Instance Method Details
#close ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/async/worker/notification.rb', line 37 def close # Due to bugs in MRI, we need to synchronize this. @mutex.synchronize do @input.close @output.close end end |
#signal ⇒ void
This method returns an undefined value.
Signal to a given task that it should resume operations.
54 55 56 57 58 |
# File 'lib/async/worker/notification.rb', line 54 def signal @mutex.synchronize do @output.syswrite(".") end end |
#wait ⇒ Object
Wait for signal to be called.
47 48 49 50 |
# File 'lib/async/worker/notification.rb', line 47 def wait wrapper = Async::IO::Generic.new(@input) wrapper.read(1) end |