source: trip-planner-front/node_modules/@npmcli/run-script/lib/signal-manager.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 812 bytes
RevLine 
[6a3a178]1const runningProcs = new Set()
2let handlersInstalled = false
3
4const forwardedSignals = [
5 'SIGINT',
6 'SIGTERM'
7]
8
9const handleSignal = signal => {
10 for (const proc of runningProcs) {
11 proc.kill(signal)
12 }
13}
14
15const setupListeners = () => {
16 for (const signal of forwardedSignals) {
17 process.on(signal, handleSignal)
18 }
19 handlersInstalled = true
20}
21
22const cleanupListeners = () => {
23 if (runningProcs.size === 0) {
24 for (const signal of forwardedSignals) {
25 process.removeListener(signal, handleSignal)
26 }
27 handlersInstalled = false
28 }
29}
30
31const add = proc => {
32 runningProcs.add(proc)
33 if (!handlersInstalled)
34 setupListeners()
35
36 proc.once('exit', () => {
37 runningProcs.delete(proc)
38 cleanupListeners()
39 })
40}
41
42module.exports = {
43 add,
44 handleSignal,
45 forwardedSignals
46}
Note: See TracBrowser for help on using the repository browser.