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
Instance Attribute Summary
Attributes inherited from Handle
Attributes inherited from Q::Promise
Instance Method Summary collapse
-
#again ⇒ Object
Resets the current repeat.
-
#initialize(reactor) ⇒ Timer
constructor
A new instance of Timer.
-
#progress(&callback) ⇒ Object
Used to update the callback to be triggered by the timer.
-
#repeat(time = nil) ⇒ Object
Set or gets the current repeat timeout Repeat is the time in milliseconds between repeated callbacks after the initial timeout fires.
-
#repeat=(time) ⇒ Object
Set the current repeat timeout Repeat is the time in milliseconds between repeated callbacks after the initial timeout fires.
-
#start(timeout, repeat = 0) ⇒ Object
Enables the timer.
-
#stop ⇒ Object
Disables the timer.
Methods inherited from Handle
#active?, #close, #closed?, #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
#catch, #finally, #ruby_catch, #value
Constructor Details
#initialize(reactor) ⇒ Timer
Returns a new instance of Timer.
12 13 14 15 16 17 18 19 20 |
# File 'lib/libuv/timer.rb', line 12 def initialize(reactor) @reactor = reactor timer_ptr = ::Libuv::Ext.allocate_handle_timer error = check_result(::Libuv::Ext.timer_init(reactor.handle, timer_ptr)) @stopped = true super(timer_ptr, error) end |
Instance Method Details
#again ⇒ Object
Resets the current repeat
52 53 54 55 56 57 58 |
# File 'lib/libuv/timer.rb', line 52 def again return if @closed error = check_result ::Libuv::Ext.timer_again(handle) reject(error) if error self end |
#progress(&callback) ⇒ Object
Used to update the callback to be triggered by the timer
88 89 90 91 |
# File 'lib/libuv/timer.rb', line 88 def progress(&callback) @callback = callback self end |
#repeat(time = nil) ⇒ Object
Set or gets the current repeat timeout Repeat is the time in milliseconds between repeated callbacks after the initial timeout fires
75 76 77 78 79 80 81 82 83 |
# File 'lib/libuv/timer.rb', line 75 def repeat(time = nil) return if @closed if time.nil? ::Libuv::Ext.timer_get_repeat(handle) else self.repeat = time self end end |
#repeat=(time) ⇒ Object
Set the current repeat timeout Repeat is the time in milliseconds between repeated callbacks after the initial timeout fires
64 65 66 67 68 69 |
# File 'lib/libuv/timer.rb', line 64 def repeat=(time) return if @closed error = check_result ::Libuv::Ext.timer_set_repeat(handle, time.to_i) reject(error) if error time end |
#start(timeout, repeat = 0) ⇒ Object
Enables the timer. A repeat of 0 means no repeat
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/libuv/timer.rb', line 26 def start(timeout, repeat = 0) return if @closed @stopped = false # prevent timeouts less than 0 (very long time otherwise as cast to an unsigned) # and you probably don't want to wait a few lifetimes timeout = timeout.to_i timeout = 0 if timeout < 0 error = check_result ::Libuv::Ext.timer_start(handle, callback(:on_timer), timeout, repeat.to_i) reject(error) if error self end |