Class: Libuv::Signal

Inherits:
Handle show all
Defined in:
lib/libuv/signal.rb

Constant Summary collapse

SIGNALS =
{
    :HUP => 1,
    :SIGHUP => 1,
    :INT => 2,
    :SIGINT => 2,
    :BREAK => 21,
    :SIGBREAK => 21,
    :WINCH => 28,
    :SIGWINCH => 28
}

Constants included from Assertions

Assertions::MSG_NO_PROC

Constants inherited from Q::Promise

Q::Promise::MAKE_PROMISE

Instance Attribute Summary

Attributes inherited from Handle

#closed, #loop, #storage

Instance Method Summary collapse

Methods inherited from Handle

#active?, #close, #closing?, #ref, #unref

Methods included from Assertions

#assert_block, #assert_boolean, #assert_type

Methods included from Resource

#check_result, #check_result!, #resolve, #to_ptr

Methods inherited from Q::DeferredPromise

#resolved?, #then

Methods inherited from Q::Promise

#catch, #finally, #progress

Constructor Details

#initialize(loop) ⇒ Signal

Returns a new instance of Signal.

Parameters:

  • loop (::Libuv::Loop)

    loop this signal handler will be associated

  • callback (Proc)

    callback to be called when the signal is triggered



22
23
24
25
26
27
28
29
# File 'lib/libuv/signal.rb', line 22

def initialize(loop)
    @loop = loop

    signal_ptr = ::Libuv::Ext.allocate_handle_signal
    error = check_result(::Libuv::Ext.signal_init(loop.handle, signal_ptr))

    super(signal_ptr, error)
end

Instance Method Details

#start(signal) ⇒ Object

Enables the signal handler.



32
33
34
35
36
37
# File 'lib/libuv/signal.rb', line 32

def start(signal)
    return if @closed
    signal = SIGNALS[signal] if signal.is_a? Symbol
    error = check_result ::Libuv::Ext.signal_start(handle, callback(:on_sig), signal)
    reject(error) if error
end

#stopObject

Disables the signal handler.



40
41
42
43
44
# File 'lib/libuv/signal.rb', line 40

def stop
    return if @closed
    error = check_result ::Libuv::Ext.signal_stop(handle)
    reject(error) if error
end