Commit 730b49c2 authored by wildfirecode13's avatar wildfirecode13

1

parent 4363286a
...@@ -7,6 +7,9 @@ export declare class Timer extends EventEmitter<any> { ...@@ -7,6 +7,9 @@ export declare class Timer extends EventEmitter<any> {
_timer: number | undefined; _timer: number | undefined;
constructor(repeatCount: number, delay?: number); constructor(repeatCount: number, delay?: number);
start(): void; start(): void;
_isPause: boolean;
pause(): void;
resume(): void;
stop(): void; stop(): void;
reset(): void; reset(): void;
} }
...@@ -21,6 +21,7 @@ var Timer = /** @class */ (function (_super) { ...@@ -21,6 +21,7 @@ var Timer = /** @class */ (function (_super) {
if (delay === void 0) { delay = 1000; } if (delay === void 0) { delay = 1000; }
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this._running = false; _this._running = false;
_this._isPause = false;
_this.repeatCount = repeatCount; _this.repeatCount = repeatCount;
_this.delay = delay; _this.delay = delay;
_this.currentCount = 0; _this.currentCount = 0;
...@@ -30,6 +31,8 @@ var Timer = /** @class */ (function (_super) { ...@@ -30,6 +31,8 @@ var Timer = /** @class */ (function (_super) {
var _this = this; var _this = this;
this._running = true; this._running = true;
this._timer = setInterval(function () { this._timer = setInterval(function () {
if (_this._isPause)
return;
_this.currentCount++; _this.currentCount++;
_this.emit("timer"); _this.emit("timer");
if (_this.currentCount == _this.repeatCount) { if (_this.currentCount == _this.repeatCount) {
...@@ -38,6 +41,12 @@ var Timer = /** @class */ (function (_super) { ...@@ -38,6 +41,12 @@ var Timer = /** @class */ (function (_super) {
} }
}, this.delay); }, this.delay);
}; };
Timer.prototype.pause = function () {
this._isPause = true;
};
Timer.prototype.resume = function () {
this._isPause = false;
};
Timer.prototype.stop = function () { Timer.prototype.stop = function () {
this._running = false; this._running = false;
clearInterval(this._timer); clearInterval(this._timer);
......
...@@ -16,6 +16,7 @@ export class Timer extends EventEmitter<any> { ...@@ -16,6 +16,7 @@ export class Timer extends EventEmitter<any> {
start() { start() {
this._running = true; this._running = true;
this._timer = setInterval(() => { this._timer = setInterval(() => {
if (this._isPause) return;
this.currentCount++; this.currentCount++;
this.emit("timer"); this.emit("timer");
if (this.currentCount == this.repeatCount) { if (this.currentCount == this.repeatCount) {
...@@ -25,6 +26,15 @@ export class Timer extends EventEmitter<any> { ...@@ -25,6 +26,15 @@ export class Timer extends EventEmitter<any> {
}, this.delay); }, this.delay);
} }
_isPause = false;
pause() {
this._isPause = true
}
resume() {
this._isPause = false
}
stop() { stop() {
this._running = false; this._running = false;
clearInterval(this._timer); 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