Sha256: 9f1ba55cc29df841dce35f768fe17ecccd92e9ce64bcd9962a5ec3044796017b

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

module Libuv
    class Check < Handle


        define_callback function: :on_check


        # @param loop [::Libuv::Loop] loop this check will be associated
        # @param callback [Proc] callback to be called on loop check
        def initialize(loop, callback = nil, &blk)
            @loop = loop
            @callback = callback || blk

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

            super(check_ptr, error)
        end

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

        # Disables the check handler.
        def stop
            return if @closed
            error = check_result ::Libuv::Ext.check_stop(handle)
            reject(error) if error
        end

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


        private


        def on_check(handle)
            begin
                @callback.call
            rescue Exception => e
                @loop.log :error, :check_cb, e
            end
        end
    end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
libuv-2.0.12 lib/libuv/check.rb
libuv-2.0.11 lib/libuv/check.rb
libuv-2.0.10 lib/libuv/check.rb
libuv-2.0.9 lib/libuv/check.rb
libuv-2.0.8 lib/libuv/check.rb
libuv-2.0.6 lib/libuv/check.rb
libuv-2.0.5 lib/libuv/check.rb
libuv-2.0.4 lib/libuv/check.rb
libuv-2.0.3 lib/libuv/check.rb
libuv-2.0.2 lib/libuv/check.rb
libuv-2.0.1 lib/libuv/check.rb
libuv-2.0.0 lib/libuv/check.rb
libuv-1.3.0 lib/libuv/check.rb