Sha256: ad1a32bdfef2fd88a7edbfcba912148e003b95304f2f701462cd854137f5d173
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
module Libuv class Idle < Handle # @param loop [::Libuv::Loop] loop this idle handler will be associated # @param callback [Proc] callback to be called when the loop is idle def initialize(loop, callback = nil, &blk) @loop = loop @callback = callback || blk idle_ptr = ::Libuv::Ext.create_handle(:uv_idle) error = check_result(::Libuv::Ext.idle_init(loop.handle, idle_ptr)) super(idle_ptr, error) end # Enables the idle handler. def start return if @closed error = check_result ::Libuv::Ext.idle_start(handle, callback(:on_idle)) reject(error) if error end # Disables the idle handler. def stop return if @closed error = check_result ::Libuv::Ext.idle_stop(handle) reject(error) if error end # Used to update the callback that will be triggered on idle # # @param callback [Proc] the callback to be called on idle trigger def progress(callback = nil, &blk) @callback = callback || blk end private def on_idle(handle, status) e = check_result(status) if e reject(e) else begin @callback.call rescue Exception => e @loop.log :error, :idle_cb, e end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
libuv-0.11.22 | lib/libuv/idle.rb |
libuv-0.11.4 | lib/libuv/idle.rb |