Timer.cancel
Timer.cancel
Function
Cancels the Timer object returned by set_timeout() or set_interval(). Returns true if the cancellation is successful, and false if it has been canceled or completed.
Syntax
ok = timer.cancel()
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| None | - | - | - | cancel() Does not accept parameters. |
Return value
| Type | Description |
|---|---|
| Bool | The timer returns true if the event is successfully canceled, otherwise it returns false. |
Example
timer = set_timeout(fn() { println(' will not execute ') }, 1000) ok = timer.cancel() // Output: true print ok
Notes
-
cancel()will not interrupt the callback in progress, it will only prevent subsequent triggering. - After the timeout callback has started or completed, call
cancel()to returnfalse. - When
self.cancel()is called internally in the interval callback, the current callback will continue to execute and will not be scheduled in the future.