Skip to content

Commit 33cb6ac

Browse files
committed
style: order watch shutdown helpers top down
1 parent 2b9c93b commit 33cb6ac

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

‎lib/watch/index.js‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ const watch = function (args, ignoreWatch, verboseWatch, followWatch) {
2727
process.removeListener('uncaughtException', onUncaughtException)
2828
}
2929

30+
function shutdown (signal) {
31+
if (stopping) return stopping
32+
allStop = true
33+
const childrenClosed = Array.from(liveChildren, closeChild)
34+
stopping = finishShutdown(signal, childrenClosed)
35+
return stopping
36+
}
37+
38+
async function finishShutdown (signal, childrenClosed) {
39+
const results = await Promise.allSettled([
40+
closeWatcher(),
41+
...childrenClosed
42+
])
43+
removeListeners()
44+
const failure = results.find(result => result.status === 'rejected')
45+
if (failure) {
46+
console.error(failure.reason)
47+
process.exitCode = 1
48+
} else {
49+
process.exitCode = signal === 'SIGINT' ? 130 : 143
50+
}
51+
}
52+
3053
async function closeWatcher () {
3154
await watcher.close()
3255
}
@@ -49,29 +72,6 @@ const watch = function (args, ignoreWatch, verboseWatch, followWatch) {
4972
}
5073
})
5174
}
52-
53-
async function finishShutdown (signal, childrenClosed) {
54-
const results = await Promise.allSettled([
55-
closeWatcher(),
56-
...childrenClosed
57-
])
58-
removeListeners()
59-
const failure = results.find(result => result.status === 'rejected')
60-
if (failure) {
61-
console.error(failure.reason)
62-
process.exitCode = 1
63-
} else {
64-
process.exitCode = signal === 'SIGINT' ? 130 : 143
65-
}
66-
}
67-
68-
function shutdown (signal) {
69-
if (stopping) return stopping
70-
allStop = true
71-
const childrenClosed = Array.from(liveChildren, closeChild)
72-
stopping = finishShutdown(signal, childrenClosed)
73-
return stopping
74-
}
7575
const onSigint = () => { shutdown('SIGINT') }
7676
const onSigterm = () => { shutdown('SIGTERM') }
7777
const stop = (watcher = null, err = null) => {

0 commit comments

Comments
 (0)