Class: Async::Worker::Notification

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

Overview

A cross-thread 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/worker/notification.rb', line 29

def initialize
  pipe = ::IO.pipe
  
  @mutex = Mutex.new
  @input = pipe.first
  @output = pipe.last
end

Instance Method Details

#closeObject



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

#signalvoid

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

#waitObject

Wait for signal to be called.

Returns:

  • (Object)


47
48
49
50
# File 'lib/async/worker/notification.rb', line 47

def wait
  wrapper = Async::IO::Generic.new(@input)
  wrapper.read(1)
end