Quarry Hill’s new kiosk joins the list this morning, and its first check fails. Owen still wants a board that shows 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 back.
Keep Every Outcome
Add Quarry Hill to the last lesson’s port, and its stand-in throws on the first check:
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);
As with gather(), one failure rejects the whole call, so about a tenth of a second in, the script stops with 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\....