Sha256: f2d45a5f5fd6a3bf0eaefa0e4ea7c828b8cbd26ec011fd56056924457a7e55cf

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

module Libuv
    class Prepare < Handle


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

            prepare_ptr = ::Libuv::Ext.create_handle(:uv_prepare)
            error = check_result(::Libuv::Ext.prepare_init(loop.handle, prepare_ptr))

            super(prepare_ptr, error)
        end

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

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

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


        private


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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
libuv-1.0.3 lib/libuv/prepare.rb
libuv-1.0.2 lib/libuv/prepare.rb
libuv-1.0.0 lib/libuv/prepare.rb
libuv-0.12.4 lib/libuv/prepare.rb
libuv-0.12.3 lib/libuv/prepare.rb