Commit 730b49c2 authored by wildfirecode13's avatar wildfirecode13

1

parent 4363286a
......@@ -7,6 +7,9 @@ export declare class Timer extends EventEmitter<any> {
_timer: number | undefined;
constructor(repeatCount: number, delay?: number);
start(): void;
_isPause: boolean;
pause(): void;
resume(): void;
stop(): void;
reset(): void;
}
......@@ -21,6 +21,7 @@ var Timer = /** @class */ (function (_super) {
if (delay === void 0) { delay = 1000; }
var _this = _super.call(this) || this;
_this._running = false;
_this._isPause = false;
_this.repeatCount = repeatCount;
_this.delay = delay;
_this.currentCount = 0;
......@@ -30,6 +31,8 @@ var Timer = /** @class */ (function (_super) {
var _this = this;
this._running = true;
this._timer = setInterval(function () {
if (_this._isPause)
return;
_this.currentCount++;
_this.emit("timer");
if (_this.currentCount == _this.repeatCount) {
......@@ -38,6 +41,12 @@ var Timer = /** @class */ (function (_super) {
}
}, this.delay);
};
Timer.prototype.pause = function () {
this._isPause = true;
};
Timer.prototype.resume = function () {
this._isPause = false;
};
Timer.prototype.stop = function () {
this._running = false;
clearInterval(this._timer);
......
......@@ -16,6 +16,7 @@ export class Timer extends EventEmitter<any> {
start() {
this._running = true;
this._timer = setInterval(() => {
if (this._isPause) return;
this.currentCount++;
this.emit("timer");
if (this.currentCount == this.repeatCount) {
......@@ -25,6 +26,15 @@ export class Timer extends EventEmitter<any> {
}, this.delay);
}
_isPause = false;
pause() {
this._isPause = true
}
resume() {
this._isPause = false
}
stop() {
this._running = false;
clearInterval(this._timer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment