1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Short Circuit Concurrently When Process Fails as a JavaScript TIL

This commit is contained in:
jbranchaud
2024-01-04 10:53:16 -06:00
parent bf814b4833
commit 83fddacd29
2 changed files with 36 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
# Short Circuit Concurrently When Process Fails
In [Run Multiple Node Scripts
Concurrently](run-multiple-node-scripts-concurrently.md), I showed how we can
get all the essential processes of our web app running concurrently in
development using the `concurrently` package.
But what happens when there is an error and one of them exits early instead of
continuing to run?
Well, the rest of the processes under the `concurrently` umbrella continue to
run as if nothing has happened. In fact, if there is enough output, you might
even miss that that one process failed since the error gets quickly pushed off
the screen.
If we need every process running for our app to work, then it would be better
to have the whole set of concurrent processes short circuit and exit early if
one fails. We can do that by giving `concurrently` the `--kill-others-on-fail`
flag.
```json
{
"scripts": {
"dev": "concurrently --kill-others-on-fail \"npm:dev:*\"",
"dev:next": "next dev",
"dev:inngest": "pnpx inngest-cli@latest dev",
"dev:mailhog": "mailhog",
}
}
```
See the [Usage
section](https://github.com/open-cli-tools/concurrently?tab=readme-ov-file#usage)
of the docs for more details.