Class: Libuv::Async

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

Constant Summary

Constants included from Assertions

Libuv::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) ⇒ Async

Returns a new instance of Async.

Parameters:

  • loop (::Libuv::Loop)

    loop this async callback will be associated



6
7
8
9
10
11
12
13
# File 'lib/libuv/async.rb', line 6

def initialize(loop, callback = nil, &blk)
    @loop = loop
    @callback = callback || blk
    async_ptr = ::Libuv::Ext.create_handle(:uv_async)
    error = check_result(::Libuv::Ext.async_init(loop.handle, async_ptr, callback(:on_async)))

    super(async_ptr, error)
end

Instance Method Details

#callObject

Triggers a notify event, calling everything in the notify chain



16
17
18
19
20
# File 'lib/libuv/async.rb', line 16

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

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

Used to update the callback that will be triggered when async is called

Parameters:

  • callback (Proc) (defaults to: nil)

    the callback to be called on loop prepare



25
26
27
# File 'lib/libuv/async.rb', line 25

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