Parallel cleanup, skip empty watches

This commit is contained in:
Chi Vinh Le
2018-07-13 11:26:19 -03:00
parent d8021f0f33
commit 9684b6046b
3 changed files with 56 additions and 47 deletions
+4 -2
View File
@@ -28,14 +28,16 @@ async function beginWatch(
function setupCleanup(watcher: Watcher, config: Config) {
["SIGINT", "SIGTERM"].forEach(signal =>
process.once(signal as any, async () => {
const cleanups = [];
if (watcher.onCleanup) {
await watcher.onCleanup();
cleanups.push(watcher.onCleanup());
}
for (const key of Object.keys(config.watchers)) {
if (config.watchers[key].executor.onCleanup) {
await config.watchers[key].executor.onCleanup!();
cleanups.push(config.watchers[key].executor.onCleanup!());
}
}
await Promise.all(cleanups);
process.exit(0);
})
);