With Promise.all(), your port asks Northgate, Eastfield, and Hollins Green at the same time and finishes in 0.9 seconds. Now Quarry Hill’s new kiosk joins the list, and its first answer of the morning is an error.
On mornings like this, Owen still wants a board that lists the three branches that answered and marks Quarry Hill as having no answer. In this lesson, you’ll keep every kiosk’s outcome and read each one the way JavaScript hands it to you.
Keep Every Result When One Kiosk Fails
Add Quarry Hill to KIOSKS with failsFirst: true, and the stand-in throws an error on its first check. The rest of the port stays as it was:
import { setTimeout as sleep } from "node:timers/promises";
const KIOSKS = {
Northgate: { delay: 120, holds: 14 },
Eastfield: { delay: 250, holds: 9 },
"Hollins Green": { delay: 900, holds: 6 },
"Quarry Hill": { delay: 80, holds: 3, failsFirst: true },
};
const BRANCHES = Object.keys(KIOSKS);
async function checkKiosk(branch) {
const kiosk = KIOSKS[branch];
await sleep(kiosk.delay);
if (kiosk.failsFirst) {
kiosk.failsFirst = false;
throw new Error(`${branch} kiosk is not answering`);
}
return { branch, holds: kiosk.holds };
}
const kiosks = await Promise.all(BRANCHES.map(checkKiosk));
console.log(kiosks);
About a tenth of a second in, when Quarry Hill’s check fails, the script stops with its error and no board:
file:///Users/you/branch-status/branch-status.js:16
throw new Error(`${branch} kiosk is not answering`);
^
Error: Quarry Hill kiosk is not answering
at checkKiosk (file:///Users/you/branch-status/branch-status.js:16:11)
at async Promise.all (index 3)
at async file:///Users/you/branch-status/branch-status.js:21:16
Node.js v26.13.0
These examples use a macOS home path. Linux paths look like /home/you/...; Windows paths look like C:\Users\you\....