123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.SigIntWatcher = void 0;
- var _class2;
- class SigIntWatcher {
- constructor() {
- this._hadSignal = false;
- this._sigintPromise = void 0;
- this._sigintHandler = void 0;
- let sigintCallback;
- this._sigintPromise = new Promise(f => sigintCallback = f);
- this._sigintHandler = () => {
- FixedNodeSIGINTHandler.off(this._sigintHandler);
- this._hadSignal = true;
- sigintCallback();
- };
- FixedNodeSIGINTHandler.on(this._sigintHandler);
- }
- promise() {
- return this._sigintPromise;
- }
- hadSignal() {
- return this._hadSignal;
- }
- disarm() {
- FixedNodeSIGINTHandler.off(this._sigintHandler);
- }
- }
- exports.SigIntWatcher = SigIntWatcher;
- class FixedNodeSIGINTHandler {
- static _install() {
- if (!this._handlerInstalled) {
- this._handlerInstalled = true;
- process.on('SIGINT', this._dispatch);
- }
- }
- static _uninstall() {
- if (this._handlerInstalled) {
- this._handlerInstalled = false;
- process.off('SIGINT', this._dispatch);
- }
- }
- static on(handler) {
- this._handlers.push(handler);
- if (this._handlers.length === 1) this._install();
- }
- static off(handler) {
- this._handlers = this._handlers.filter(h => h !== handler);
- if (!this._ignoreNextSIGINTs && !this._handlers.length) this._uninstall();
- }
- }
- _class2 = FixedNodeSIGINTHandler;
- FixedNodeSIGINTHandler._handlers = [];
- FixedNodeSIGINTHandler._ignoreNextSIGINTs = false;
- FixedNodeSIGINTHandler._handlerInstalled = false;
- FixedNodeSIGINTHandler._dispatch = () => {
- if (_class2._ignoreNextSIGINTs) return;
- _class2._ignoreNextSIGINTs = true;
- setTimeout(() => {
- _class2._ignoreNextSIGINTs = false;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!_class2._handlers.length) _class2._uninstall();
- }, 1000);
- for (const handler of _class2._handlers) handler();
- };
|