UNPKG

@zodash/hold-on

Version:

Make progress hold on for jobs

34 lines (33 loc) 941 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.holdOn = void 0; const http = require("http"); const fs = require("fs"); function listenExit(callback) { // 中断 (Ctrl + C) process.on('SIGINT', callback); // 退出 (Ctrl + \) process.on('SIGQUIT', callback); // 中断断线 Terminal Close process.on('SIGHUP', callback); // Windows => Ctrl + Break process.on('SIGBREAK', callback); } function cleanUnixSocket(unixSocketPath) { if (fs.existsSync(unixSocketPath)) { fs.unlinkSync(unixSocketPath); } } function holdOn(unixSocketPath, onExit = () => null) { // cleanUnixSocket(unixSocketPath); const server = http.createServer(); server.listen(unixSocketPath); // @TODO listenExit(() => { cleanUnixSocket(unixSocketPath); onExit.apply(null); }); return server; } exports.holdOn = holdOn; exports.default = holdOn;