Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created January 10, 2026 20:59
Show Gist options
  • Select an option

  • Save jcoglan/3e27b5fe676d11f3040e8a50afbf3316 to your computer and use it in GitHub Desktop.

Select an option

Save jcoglan/3e27b5fe676d11f3040e8a50afbf3316 to your computer and use it in GitHub Desktop.
'use strict'
function run (fn) {
let { promise, resolve, reject } = Promise.withResolvers()
let p = fn()
p.then(resolve, reject)
// p.finally(() => {}) // -- uncomment for a surprise
return promise
}
async function main () {
try {
await run(() => Promise.reject(new Error('oh no')))
} catch (err) {
console.log('failed')
}
}
main().then(
() => console.log('ok'),
() => console.log('not ok')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment