ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / runner / sigIntWatcher.js
Source Blame History 96 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var sigIntWatcher_exports = {};
f7eb47b… lmata 20 __export(sigIntWatcher_exports, {
f7eb47b… lmata 21 SigIntWatcher: () => SigIntWatcher
f7eb47b… lmata 22 });
f7eb47b… lmata 23 module.exports = __toCommonJS(sigIntWatcher_exports);
f7eb47b… lmata 24 class SigIntWatcher {
f7eb47b… lmata 25 constructor() {
f7eb47b… lmata 26 this._hadSignal = false;
f7eb47b… lmata 27 let sigintCallback;
f7eb47b… lmata 28 this._sigintPromise = new Promise((f) => sigintCallback = f);
f7eb47b… lmata 29 this._sigintHandler = () => {
f7eb47b… lmata 30 FixedNodeSIGINTHandler.off(this._sigintHandler);
f7eb47b… lmata 31 this._hadSignal = true;
f7eb47b… lmata 32 sigintCallback();
f7eb47b… lmata 33 };
f7eb47b… lmata 34 FixedNodeSIGINTHandler.on(this._sigintHandler);
f7eb47b… lmata 35 }
f7eb47b… lmata 36 promise() {
f7eb47b… lmata 37 return this._sigintPromise;
f7eb47b… lmata 38 }
f7eb47b… lmata 39 hadSignal() {
f7eb47b… lmata 40 return this._hadSignal;
f7eb47b… lmata 41 }
f7eb47b… lmata 42 disarm() {
f7eb47b… lmata 43 FixedNodeSIGINTHandler.off(this._sigintHandler);
f7eb47b… lmata 44 }
f7eb47b… lmata 45 }
f7eb47b… lmata 46 class FixedNodeSIGINTHandler {
f7eb47b… lmata 47 static {
f7eb47b… lmata 48 this._handlers = [];
f7eb47b… lmata 49 }
f7eb47b… lmata 50 static {
f7eb47b… lmata 51 this._ignoreNextSIGINTs = false;
f7eb47b… lmata 52 }
f7eb47b… lmata 53 static {
f7eb47b… lmata 54 this._handlerInstalled = false;
f7eb47b… lmata 55 }
f7eb47b… lmata 56 static {
f7eb47b… lmata 57 this._dispatch = () => {
f7eb47b… lmata 58 if (this._ignoreNextSIGINTs)
f7eb47b… lmata 59 return;
f7eb47b… lmata 60 this._ignoreNextSIGINTs = true;
f7eb47b… lmata 61 setTimeout(() => {
f7eb47b… lmata 62 this._ignoreNextSIGINTs = false;
f7eb47b… lmata 63 if (!this._handlers.length)
f7eb47b… lmata 64 this._uninstall();
f7eb47b… lmata 65 }, 1e3);
f7eb47b… lmata 66 for (const handler of this._handlers)
f7eb47b… lmata 67 handler();
f7eb47b… lmata 68 };
f7eb47b… lmata 69 }
f7eb47b… lmata 70 static _install() {
f7eb47b… lmata 71 if (!this._handlerInstalled) {
f7eb47b… lmata 72 this._handlerInstalled = true;
f7eb47b… lmata 73 process.on("SIGINT", this._dispatch);
f7eb47b… lmata 74 }
f7eb47b… lmata 75 }
f7eb47b… lmata 76 static _uninstall() {
f7eb47b… lmata 77 if (this._handlerInstalled) {
f7eb47b… lmata 78 this._handlerInstalled = false;
f7eb47b… lmata 79 process.off("SIGINT", this._dispatch);
f7eb47b… lmata 80 }
f7eb47b… lmata 81 }
f7eb47b… lmata 82 static on(handler) {
f7eb47b… lmata 83 this._handlers.push(handler);
f7eb47b… lmata 84 if (this._handlers.length === 1)
f7eb47b… lmata 85 this._install();
f7eb47b… lmata 86 }
f7eb47b… lmata 87 static off(handler) {
f7eb47b… lmata 88 this._handlers = this._handlers.filter((h) => h !== handler);
f7eb47b… lmata 89 if (!this._ignoreNextSIGINTs && !this._handlers.length)
f7eb47b… lmata 90 this._uninstall();
f7eb47b… lmata 91 }
f7eb47b… lmata 92 }
f7eb47b… lmata 93 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 94 0 && (module.exports = {
f7eb47b… lmata 95 SigIntWatcher
f7eb47b… lmata 96 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button