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



19
20
21
22
23
24
25
26
# File 'lib/libuv/signal.rb', line 19

def initialize(loop)
    @loop = loop

    signal_ptr = ::Libuv::Ext.create_handle(:uv_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.



29
30
31
32
33
34
# File 'lib/libuv/signal.rb', line 29

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.



37
38
39
40
41
# File 'lib/libuv/signal.rb', line 37

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