From 83fddacd29635913da1d6d1bda66c1d69c51ee2d Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 4 Jan 2024 10:53:16 -0600 Subject: [PATCH] Add Short Circuit Concurrently When Process Fails as a JavaScript TIL --- README.md | 3 +- ...circuit-concurrently-when-process-fails.md | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 javascript/short-circuit-concurrently-when-process-fails.md diff --git a/README.md b/README.md index 4bccbbd..6c76cde 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1362 TILs and counting..._ +_1363 TILs and counting..._ --- @@ -475,6 +475,7 @@ _1362 TILs and counting..._ - [Run Multiple Node Scripts Concurrently](javascript/run-multiple-node-scripts-concurrently.md) - [Running ES6 Specs With Mocha](javascript/running-es6-specs-with-mocha.md) - [Scoping Variables With A Block Statement](javascript/scoping-variables-with-a-block-statement.md) +- [Short Circuit Concurrently When Process Fails](javascript/short-circuit-concurrently-when-process-fails.md) - [Sleep For A Bit In Async Code](javascript/sleep-for-a-bit-in-async-code.md) - [Sorting Arrays Of Objects With Lodash](javascript/sorting-arrays-of-objects-with-lodash.md) - [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md) diff --git a/javascript/short-circuit-concurrently-when-process-fails.md b/javascript/short-circuit-concurrently-when-process-fails.md new file mode 100644 index 0000000..537432e --- /dev/null +++ b/javascript/short-circuit-concurrently-when-process-fails.md @@ -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.