set_timeout

set_timeout

set_timeout

Function

Registers a one-time deferred callback and returns a Timer object immediately. After the callback expires, it will be executed once by the single-threaded event loop of the VM to which it belongs, and the callback return value will be ignored.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
fnFnYesNoneDelayed execution of the BT function.
delay_msIntNo0Delay in milliseconds; negative numbers are treated as 0.

Return value

TypeDescription
TimerTimer handle, you can call cancel() to cancel the callback that has not yet been triggered.

Example

Notes

  • set_timeout() will not execute the callback synchronously; when delay_ms is 0, it will be delivered to the event queue as soon as possible.
  • CLI scripts with an active timeout will remain in progress until the callback execution completes or is cancelled.
  • A timer cannot be created in the Web request context, and the VM will be released after the request ends.
  • For the method of canceling the timer, see Timer.cancel.