Class: Libuv::Timer
- Inherits:
-
Handle
- Object
- Q::Promise
- Q::DeferredPromise
- Handle
- Libuv::Timer
- Includes:
- Assertions
- Defined in:
- lib/libuv/timer.rb
Constant Summary collapse
- TIMEOUT_ERROR =
"timeout must be an Integer".freeze
- REPEAT_ERROR =
"repeat must be an Integer".freeze
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 included from Assertions
#assert_block, #assert_boolean, #assert_type
Methods inherited from Handle
#active?, #close, #closing?, #ref, #unref
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.
12 13 14 15 16 17 18 19 |
# File 'lib/libuv/timer.rb', line 12 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)) super(timer_ptr, error) end |
Instance Method Details
#again ⇒ Object
Resets the current repeat
43 44 45 46 47 |
# File 'lib/libuv/timer.rb', line 43 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
66 67 68 |
# File 'lib/libuv/timer.rb', line 66 def progress(callback = nil, &blk) @callback = callback || blk end |
#repeat ⇒ Object
Returns the current repeat timeout
58 59 60 61 |
# File 'lib/libuv/timer.rb', line 58 def repeat return if @closed ::Libuv::Ext.timer_get_repeat(handle) end |
#repeat=(repeat) ⇒ Object
Updates the repeat timeout
50 51 52 53 54 55 |
# File 'lib/libuv/timer.rb', line 50 def repeat=(repeat) return if @closed assert_type(Integer, repeat, REPEAT_ERROR) 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
25 26 27 28 29 30 31 32 33 |
# File 'lib/libuv/timer.rb', line 25 def start(timeout, repeat = 0) return if @closed assert_type(Integer, timeout, TIMEOUT_ERROR) assert_type(Integer, repeat, REPEAT_ERROR) error = check_result ::Libuv::Ext.timer_start(handle, callback(:on_timer), timeout, repeat) reject(error) if error end |