Class: Libuv::Check

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

Constant Summary

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

Constructor Details

#initialize(loop, callback = nil, &blk) ⇒ Check

Returns a new instance of Check.

Parameters:

  • loop (::Libuv::Loop)

    loop this check will be associated

  • callback (Proc) (defaults to: nil)

    callback to be called on loop check



7
8
9
10
11
12
13
14
15
# File 'lib/libuv/check.rb', line 7

def initialize(loop, callback = nil, &blk)
    @loop = loop
    @callback = callback || blk

    check_ptr = ::Libuv::Ext.create_handle(:uv_check)
    error = check_result(::Libuv::Ext.check_init(loop.handle, check_ptr))

    super(check_ptr, error)
end

Instance Method Details

#progress(callback = nil, &blk) ⇒ Object

Used to update the callback that will be triggered on loop check

Parameters:

  • callback (Proc) (defaults to: nil)

    the callback to be called on loop check



34
35
36
# File 'lib/libuv/check.rb', line 34

def progress(callback = nil, &blk)
    @callback = callback || blk
end

#startObject

Enables the check handler.



18
19
20
21
22
# File 'lib/libuv/check.rb', line 18

def start
    return if @closed
    error = check_result ::Libuv::Ext.check_start(handle, callback(:on_check))
    reject(error) if error
end

#stopObject

Disables the check handler.



25
26
27
28
29
# File 'lib/libuv/check.rb', line 25

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