Files
NapCatQQ/.pnpm-store/v3/files/d8/cadd60b08188585a97ede293b2631f2b09532dacc6414ebdda6033a5d78e6303e8416056d19659295b8199cfecf64b263f044c17722813f5097ee4d35fe700
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

118 lines
3.6 KiB
Plaintext

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getScheduler = exports.TimeoutLatch = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
// Setting / Unsetting timeouts for every keystroke was a significant overhead
// Inspired from https://github.com/iostreamer-X/timeout-latch
var TimeoutLatch = exports.TimeoutLatch = /*#__PURE__*/function () {
function TimeoutLatch(callback, timeoutMS) {
(0, _classCallCheck2["default"])(this, TimeoutLatch);
(0, _defineProperty2["default"])(this, "timeLeftMS", void 0);
(0, _defineProperty2["default"])(this, "timeoutMS", void 0);
(0, _defineProperty2["default"])(this, "isCancelled", false);
(0, _defineProperty2["default"])(this, "isTimeExhausted", false);
(0, _defineProperty2["default"])(this, "callbacks", []);
this.timeLeftMS = timeoutMS;
this.timeoutMS = timeoutMS;
this.callbacks.push(callback);
}
return (0, _createClass2["default"])(TimeoutLatch, [{
key: "tick",
value: function tick() {
if (!this.isCancelled && !this.isTimeExhausted) {
this.timeLeftMS--;
if (this.timeLeftMS <= 0) {
this.isTimeExhausted = true;
var callbacks = this.callbacks.slice();
this.callbacks.length = 0;
callbacks.forEach(function (callback) {
try {
callback();
} catch (error) {
console.error('TimeoutLatch callback error:', error);
}
});
}
}
}
}, {
key: "cancel",
value: function cancel() {
this.isCancelled = true;
this.callbacks.length = 0;
}
}, {
key: "reset",
value: function reset() {
this.timeLeftMS = this.timeoutMS;
this.isCancelled = false;
this.isTimeExhausted = false;
}
}, {
key: "isDone",
get: function get() {
return this.isCancelled || this.isTimeExhausted;
}
}]);
}();
var Scheduler = /*#__PURE__*/function () {
function Scheduler() {
(0, _classCallCheck2["default"])(this, Scheduler);
(0, _defineProperty2["default"])(this, "interval", null);
(0, _defineProperty2["default"])(this, "latches", new Set());
}
return (0, _createClass2["default"])(Scheduler, [{
key: "add",
value: function add(latch) {
this.latches.add(latch);
this.start();
}
}, {
key: "remove",
value: function remove(latch) {
this.latches["delete"](latch);
if (this.latches.size === 0) {
this.stop();
}
}
}, {
key: "start",
value: function start() {
var _this = this;
if (this.interval === null) {
this.interval = setInterval(function () {
_this.latches.forEach(function (latch) {
latch.tick();
if (latch.isDone) {
_this.remove(latch);
}
});
}, 1);
}
}
}, {
key: "stop",
value: function stop() {
if (this.interval !== null) {
clearInterval(this.interval);
this.interval = null;
}
}
}]);
}();
var globalScheduler = null;
var getScheduler = exports.getScheduler = function getScheduler() {
if (typeof window === 'undefined') {
return new Scheduler();
}
if (!globalScheduler) {
globalScheduler = new Scheduler();
}
return globalScheduler;
};