Skip to content

Instantly share code, notes, and snippets.

View eroosenmaallen's full-sized avatar

Eddie Roosenmaallen eroosenmaallen

View GitHub Profile
eroosenmaallen / await-foreach.js
Last active September 20, 2023 14:33
Interaction between async and Array.forEach/.reduce
View await-foreach.js
#! /usr/bin/env node
const arr = [1, 2, 3, 4, 5, 6];
async function main()
/** If this block is uncommented, all 6 lines print at the same time,
* after "Done" is printed, even if the forEach is awaited. Nothing awaits
* the individual Promises created for each element.
eroosenmaallen / unhandled.js
Last active May 29, 2019 13:58
Demonstration of UnhandledPromiseRejectionWarning
View unhandled.js
// Do a thing poorly and asynchronously
async function doAThingBadly() {
throw new Error('It broke')
// node uncaught.js
// Try to await a thing. It will throw, but it seems like the Error
// should bubble up to be caught in the higher-up try-catch, right? Right?
async function doAThing() {