`timer` calls a callback repeatedly from a timer thread.
The callback receives one argument: the timer call count. The first callback receives `1`.
`timer` is not cloneable because it owns active timer state and a callback reference.
Creates a timer object using a callable object.
| Argument | Type | Description |
|---|---|---|
| `callback` | callable object | Function reference, method reference, or other object that implements `call(count)`. |
Returns: timer object.
Example:
function OnTimer(count) { print('timer ', count); } t = timer(OnTimer);
`timer` has no object-specific properties.
Use `is_running()` to check whether the timer is active.
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
`clone()` is not supported for `timer`.
Starts the timer.
| Argument | Type | Description |
|---|---|---|
| `intervalMs` | number | Timer interval in milliseconds. Values less than or equal to zero are treated as `1`. |
Returns: boolean-style number.
Example:
t = timer(OnTimer); t.start(1000);
Starts the timer with a repeat count.
| Argument | Type | Description |
|---|---|---|
| `intervalMs` | number | Timer interval in milliseconds. Values less than or equal to zero are treated as `1`. |
| `count` | number | Number of callbacks. Values less than or equal to zero mean continuous periodic execution. |
Returns: boolean-style number.
Example:
t = timer(OnTimer); t.start(500, 3); // call OnTimer three times
Stops the timer.
| Item | Description |
|---|---|
| Syntax | `timer.stop()` |
| Arguments | none |
| Returns | boolean-style number |
Returns `true` if the timer was running, otherwise returns `false`.
Example:
t.stop();
Returns true while the timer is running.
| Item | Description |
|---|---|
| Syntax | `timer.is_running()` |
| Arguments | none |
| Returns | boolean-style number |
Example:
if (t.is_running()) { print('timer is active'); }
Returns a short text summary of timer methods.
| Item | Description |
|---|---|
| Syntax | `timer.help()` |
| Arguments | none |
| Returns | string |