Class: Toybox::Timer::Timer

Inherits:
Lang::Object show all

Overview

A Timer object will invoke a callback function after a specified number of milliseconds.

There are two types of timers: one-shot or repeating. A one-shot Timer will only run once after the Timer expires, while a repeating Timer will invoke the callback function every n milliseconds until stop() is called. If a repeating Timer fails to run before its next execution time, then any missed executions will be skipped.

The number of available timers (default 3) and the minimum time value (default 50 ms) depends on the host system. An error will occur if too many timers are set.

Examples:

Create a counter that increments by one each second

using Toybox.Timer;
var myCount =  0;

function timerCallback() {
    myCount += 1;
    Ui.requestUpdate();
}

function onLayout(dc) {
    var myTimer = new Timer.Timer();
    myTimer.start(method(:timerCallback), 1000, true);
}

Since:

  • 1.0.0

Months of the year collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Instance Method Details

start(callback, time, repeat) ⇒ Object

Start the Timer.

Parameters:

Since:

  • 1.0.0


11160
11161
# File 'Monkeybrains.rb', line 11160

def start(callback, time, repeat)
end

stopObject

Stops the Timer from running.

This only needs to be called for repeating timers. A Timer can be started again by calling start().

Since:

  • 1.0.0


11168
11169
# File 'Monkeybrains.rb', line 11168

def stop()
end