Sha256: a2b3524bb773cd7bed068ab5819db66d0fdcc5d230c82db659031939fb6df88b

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

module Libuv
    class Async < Handle


        # @param loop [::Libuv::Loop] loop this async callback will be associated
        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

        # Triggers a notify event, calling everything in the notify chain
        def call
            return if @closed
            error = check_result ::Libuv::Ext.async_send(handle)
            reject(error) if error
        end

        # Used to update the callback that will be triggered when async is called
        #
        # @param callback [Proc] the callback to be called on loop prepare
        def progress(callback = nil, &blk)
            @callback = callback || blk
        end


        private


        def on_async(handle, status)
            e = check_result(status)

            if e
                reject(e)
            else
                begin
                    @callback.call
                rescue Exception => e
                    @loop.log :error, :async_cb, e
                end
            end
        end
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
libuv-0.12.2 lib/libuv/async.rb
libuv-0.12.0 lib/libuv/async.rb
libuv-0.11.21 lib/libuv/async.rb
libuv-0.11.20 lib/libuv/async.rb
libuv-0.11.19 lib/libuv/async.rb
libuv-0.11.18 lib/libuv/async.rb
libuv-0.11.7 lib/libuv/async.rb
libuv-0.11.5 lib/libuv/async.rb
libuv-0.11.3 lib/libuv/async.rb
libuv-0.11.2 lib/libuv/async.rb
libuv-0.11.1 lib/libuv/async.rb
libuv-0.11.0 lib/libuv/async.rb
libuv-0.10.3 lib/libuv/async.rb
libuv-0.10.2 lib/libuv/async.rb