Function createTimeoutWith

Creates a non-running (paused) timer which will execute a function or specified piece of code when enabled once the timer expires. The overrideFn will be used to create the timer, this is simular to using scheduleTimeoutWith but the timer is not enabled (running) and you MUST call refresh to start the timer.

The timer may be cancelled (cleared) by calling the cancel() function on the returned ITimerHandler, or you can "reschedule" and/or "restart" the timer by calling the refresh() function on the returned ITimerHandler instance

0.7.0

setTimeout override function this will be called instead of the setTimeout, if the value of overrideFn is null or undefined it will revert back to the native setTimeout. May also be an array with contains both the setTimeout and clearTimeout override functions, if either is not provided the default native functions will be used

The function to be executed after the timer expires.

The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.

Additional arguments which are passed through to the function specified by callback.

A ITimerHandler instance which can be used to cancel the timeout.

let timeoutCalled = false;
// Your own "setTimeout" implementation to allow you to perform additional operations or possible wrap
// the callback to add timings.
function newSetTimeoutFn(callback: TimeoutOverrideFn) {
overrideCalled ++;
return setTimeout(callback, timeout);
}

let theTimeout = createTimeoutWith(newSetTimeoutFn, () => {
// This callback will be called after 100ms as this uses setTimeout()
timeoutCalled = true;
}, 100);

// As the timer is not started you will need to call "refresh" to start the timer
theTimeout.refresh();

// or set enabled to true
theTimeout.enabled = true;
let timeoutCalled = false;
// Your own "setTimeout" implementation to allow you to perform additional operations or possible wrap
// the callback to add timings.
function newSetTimeoutFn(callback: TimeoutOverrideFn) {
overrideCalled ++;
return setTimeout(callback, timeout);
}

// Your own "clearTimeout" implementation to allow you to perform additional operations or possible wrap
// the callback to add timings.
function newClearTimeoutFn(timeoutId: number) {
overrideCalled ++;
return clearTimeout( timeout);
}

let theTimeout = createTimeoutWith([newSetTimeoutFn, newClearTimeoutFn], () => {
// This callback will be called after 100ms as this uses setTimeout()
timeoutCalled = true;
}, 100);

// As the timer is not started you will need to call "refresh" to start the timer
theTimeout.refresh();

// or set enabled to true
theTimeout.enabled = true;
  • Creates a non-running (paused) timer which will execute a function or specified piece of code when enabled once the timer expires. The overrideFn will be used to create the timer, this is simular to using scheduleTimeoutWith but the timer is not enabled (running) and you MUST call refresh to start the timer.

    The timer may be cancelled (cleared) by calling the cancel() function on the returned ITimerHandler, or you can "reschedule" and/or "restart" the timer by calling the refresh() function on the returned ITimerHandler instance

    Type Parameters

    • A extends any[]

    Parameters

    • overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs

      setTimeout override function this will be called instead of the setTimeout, if the value of overrideFn is null or undefined it will revert back to the native setTimeout. May also be an array with contains both the setTimeout and clearTimeout override functions, if either is not provided the default native functions will be used

    • callback: ((...args: A) => void)

      The function to be executed after the timer expires.

        • (...args): void
        • Parameters

          • Rest...args: A

          Returns void

    • timeout: number

      The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.

    • Rest...args: A

      Additional arguments which are passed through to the function specified by callback.

    Returns ITimerHandler

    A ITimerHandler instance which can be used to cancel the timeout.

    0.7.0

    let timeoutCalled = false;
    // Your own "setTimeout" implementation to allow you to perform additional operations or possible wrap
    // the callback to add timings.
    function newSetTimeoutFn(callback: TimeoutOverrideFn) {
    overrideCalled ++;
    return setTimeout(callback, timeout);
    }

    let theTimeout = createTimeoutWith(newSetTimeoutFn, () => {
    // This callback will be called after 100ms as this uses setTimeout()
    timeoutCalled = true;
    }, 100);

    // As the timer is not started you will need to call "refresh" to start the timer
    theTimeout.refresh();

    // or set enabled to true
    theTimeout.enabled = true;
    let timeoutCalled = false;
    // Your own "setTimeout" implementation to allow you to perform additional operations or possible wrap
    // the callback to add timings.
    function newSetTimeoutFn(callback: TimeoutOverrideFn) {
    overrideCalled ++;
    return setTimeout(callback, timeout);
    }

    // Your own "clearTimeout" implementation to allow you to perform additional operations or possible wrap
    // the callback to add timings.
    function newClearTimeoutFn(timeoutId: number) {
    overrideCalled ++;
    return clearTimeout( timeout);
    }

    let theTimeout = createTimeoutWith([newSetTimeoutFn, newClearTimeoutFn], () => {
    // This callback will be called after 100ms as this uses setTimeout()
    timeoutCalled = true;
    }, 100);

    // As the timer is not started you will need to call "refresh" to start the timer
    theTimeout.refresh();

    // or set enabled to true
    theTimeout.enabled = true;