Namespace: TimerUtils

Oracle® JavaScript Extension Toolkit (JET)
5.0.0

E90577-01

QuickNav

PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

TimerUtils

Version:
  • 5.0.0
Since:
  • 4.1.0
Module:
  • ojcore
Timing related utilities
Since:
  • 4.1.0

Methods

(static) getTimer(timeout) → {Timer}

Get a Timer object with the given timeout in milliseconds. The Promise associated with the timer is resolved when the timeout window expires, or if the clear() function is called. This is useful for when code needs to be executed on timeout (setTimeout) and must handle cleanup tasks such as clearing BusyState when the timer expires or is canceled.
Parameters:
Name Type Description
timeout number The timeout value in milliseconds to wait before the promise is resolved.
Returns:
A Timer object which encapsulates the Promise that will be resolved once the timeout has been exceeded or cleared.
Type
Timer
Examples

Get a timer to execute code on normal timeout and cancelation. If the timeout occurs normally (not canceled), both callbacks are executed and the value of the 'completed' parameter will be true.

var timer = oj.TimerUtils.getTimer(1000);
timer.getPromise().then(function(completed) {
    if (completed) {
      // Delayed code
    }
  })
timer.getPromise().then(function() {
  // Code always to be run
})

Get a timer to execute code on normal timeout and cancelation. In this example, the timer is canceled before its timeout expires, and the value of the 'completed' parameter will be false.

var timer = oj.TimerUtils.getTimer(1000);
timer.getPromise()
  .then(function(completed) {
    if (completed) {
      // Delayed code
    }
  })
timer.getPromise()
  .then(function() {
    // Code always to be run
  })
...
timer.clear(); // timer cleared before timeout expires