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
Attributes inherited from Q::Promise
Instance Method Summary collapse
-
#again ⇒ Object
Resets the current repeat.
-
#initialize(reactor, callback = nil, &blk) ⇒ Timer
constructor
A new instance of Timer.
-
#progress(callback = nil, &blk) ⇒ 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, callback = nil, &blk) ⇒ Timer
Returns a new instance of Timer.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/libuv/timer.rb', line 12 def initialize(reactor, callback = nil, &blk) @reactor = reactor @callback = callback || blk 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
53 54 55 56 57 58 59 |
# File 'lib/libuv/timer.rb', line 53 def again return if @closed error = check_result ::Libuv::Ext.timer_again(handle) reject(error) if error self end |
#progress(callback = nil, &blk) ⇒ Object
Used to update the callback to be triggered by the timer
89 90 91 92 93 |
# File 'lib/libuv/timer.rb', line 89 def progress(callback = nil, &blk) @callback = callback || blk 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
76 77 78 79 80 81 82 83 84 |
# File 'lib/libuv/timer.rb', line 76 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
65 66 67 68 69 70 |
# File 'lib/libuv/timer.rb', line 65 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/libuv/timer.rb', line 27 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 |