tsbase
Version:
Base class libraries for TypeScript
44 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timer = void 0;
var tslib_1 = require("tslib");
var Timer = /** @class */ (function () {
function Timer(interval) {
this.AutoReset = false;
this.Enabled = false;
this.Elapsed = new Array();
interval ? this.Interval = interval : this.Interval = 0;
}
Timer.prototype.Start = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new Promise(function (resolve) {
_this.Enabled = _this.Elapsed.length >= 1;
var executer = setInterval(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
this.Elapsed.forEach(function (item) { return item(); });
if (!this.AutoReset) {
this.Enabled = false;
}
if (!this.Enabled) {
clearInterval(executer);
resolve();
}
return [2 /*return*/];
});
}); }, _this.Interval);
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
Timer.prototype.Stop = function () {
this.Enabled = false;
};
return Timer;
}());
exports.Timer = Timer;
//# sourceMappingURL=Timer.js.map