@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
66 lines • 1.98 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Utilities
*/
/** Notifies handler after a set interval.
* @public
* @deprecated in 4.15.0. Used internally.
*/
export class Timer {
_delay;
_isRunning = false;
_timerId = 0;
// eslint-disable-next-line @typescript-eslint/no-deprecated
_onExecute;
/**
* Creates a new Timer.
* @param msDelay Time interval in milliseconds after which handler will be notified.
*/
constructor(msDelay) {
this._delay = msDelay;
}
/** Indicates whether the timer is running */
get isRunning() {
return this._isRunning;
}
/** Time interval in milliseconds after which handler will be notified. */
get delay() {
return this._delay;
}
set delay(ms) {
this._delay = ms;
}
/** Set handler that is called after a set interval. */
// eslint-disable-next-line @typescript-eslint/no-deprecated
setOnExecute(onExecute) {
this._onExecute = onExecute;
}
/** Starts this Timer. */
start() {
if (this._isRunning)
this.clearTimeout();
this._isRunning = true;
this.setTimeout();
}
/** Stops this Timer. */
stop() {
if (!this._isRunning)
return;
this._isRunning = false;
this.clearTimeout();
}
execute() {
this._onExecute && this._onExecute();
this._isRunning = false;
}
setTimeout() {
this._timerId = window.setTimeout(() => this.execute(), this._delay);
}
clearTimeout() {
window.clearTimeout(this._timerId);
}
}
//# sourceMappingURL=Timer.js.map