Class: Libuv::Timer
- Inherits:
-
Handle
- Object
- Q::Promise
- Q::DeferredPromise
- Handle
- Libuv::Timer
- Defined in:
- lib/libuv/timer.rb
Constant Summary
Constants included from Assertions
Constants inherited from Q::Promise
Instance Attribute Summary
Attributes inherited from Handle
Instance Method Summary collapse
-
#again ⇒ Object
Resets the current repeat.
-
#initialize(loop, callback = nil) ⇒ Timer
constructor
A new instance of Timer.
-
#progress(callback = nil, &blk) ⇒ Object
Used to update the callback to be triggered by the timer.
-
#repeat ⇒ Object
Returns the current repeat timeout.
-
#repeat=(repeat) ⇒ Object
Updates the repeat timeout.
-
#start(timeout, repeat = 0) ⇒ Object
Enables the timer.
-
#stop ⇒ Object
Disables the timer.
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
Methods inherited from Q::Promise
Constructor Details
#initialize(loop, callback = nil) ⇒ Timer
Returns a new instance of Timer.
6 7 8 9 10 11 12 13 14 |
# File 'lib/libuv/timer.rb', line 6 def initialize(loop, callback = nil) @loop, @callback = loop, callback timer_ptr = ::Libuv::Ext.create_handle(:uv_timer) error = check_result(::Libuv::Ext.timer_init(loop.handle, timer_ptr)) @stopped = true super(timer_ptr, error) end |
Instance Method Details
#again ⇒ Object
Resets the current repeat
40 41 42 43 44 |
# File 'lib/libuv/timer.rb', line 40 def again return if @closed error = check_result ::Libuv::Ext.timer_again(handle) reject(error) if error end |
#progress(callback = nil, &blk) ⇒ Object
Used to update the callback to be triggered by the timer
63 64 65 |
# File 'lib/libuv/timer.rb', line 63 def progress(callback = nil, &blk) @callback = callback || blk end |
#repeat ⇒ Object
Returns the current repeat timeout
55 56 57 58 |
# File 'lib/libuv/timer.rb', line 55 def repeat return if @closed ::Libuv::Ext.timer_get_repeat(handle) end |
#repeat=(repeat) ⇒ Object
Updates the repeat timeout
47 48 49 50 51 52 |
# File 'lib/libuv/timer.rb', line 47 def repeat=(repeat) return if @closed repeat = repeat.to_i check_result ::Libuv::Ext.timer_set_repeat(handle, repeat) reject(error) if error end |
#start(timeout, repeat = 0) ⇒ Object
Enables the timer. A repeat of 0 means no repeat
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/libuv/timer.rb', line 20 def start(timeout, repeat = 0) return if @closed @stopped = false timeout = timeout.to_i repeat = repeat.to_i error = check_result ::Libuv::Ext.timer_start(handle, callback(:on_timer), timeout, repeat) reject(error) if error end |
#stop ⇒ Object
Disables the timer.
32 33 34 35 36 37 |
# File 'lib/libuv/timer.rb', line 32 def stop return if @stopped || @closed @stopped = true error = check_result ::Libuv::Ext.timer_stop(handle) reject(error) if error end |