-
-
Notifications
You must be signed in to change notification settings - Fork 253
Description
Description
I'm using concurrently to run 2 commands in parallel on my application:
- Watch's application code using
swc - A plain
node ./dist/server.jscommand which starts my HTTP server.
I wanted to implement a logic of which every time SWC outputs a successful watch compilation output, to restart the NodeJS server by combining the Command object kill/start API.
Here is a simplified example of my code:
const commands = [
{ name: 'SWC watcher', command: 'swc src -d dist/server -w -D' },
{ name: 'HTTP Server', command: 'node -r dotenv/config ./dist/server/index.js' },
];
const concurrency = concurrently(commands, {
killOthers: ['failure'],
prefixColors: ['magenta', 'yellow']
});
let shouldRestart = false;
const [watcherCommand, serverCommand] = concurrency.commands;
serverCommand.close.subscribe(() => {
if (shouldRestart) {
shouldRestart = false;
serverCommand.start();
}
});
watcherCommand.stdout.subscribe((data) => {
const input = data.toString().trim();
if (compilationCompleteRegex.test(input)) { // Detects compilation end output
shouldRestart = true;
serverCommand.kill('SIGTERM'); // HTTP listens and gracefully shuts down
}
});Actual Behaviour
After 2 restarts the concurrency top command resolves as both commands was terminated but in fact, both commands still up and running.
Some Technical details
It seems that CompletionListener.listen method actually uses bufferCount to assume its commands were terminated by counting the close events but programmatically using Command.start/Command.kill API's can cause un-expected behaviour in this manner as nothing was actually terminated rather solely restarted
Thanks in advanced 🙏