If you have an issue comment / PR description on GitHub, it doesn't automatically get anchors / IDs that you could link to:
What I like to do is to add a visible #
character like this:
someAsyncThing() | |
.then(result => { ... }) |
await Promise.reject(new Error('Boom')); |
throw new Error('Boom'); |
async function () { | |
// someAsyncThing being a function that returns a promise | |
const result = await someAsyncThing(); | |
return result.value; | |
} |
function () { | |
// someAsyncThing being a function that returns a promise | |
return someAsyncThing() | |
.then(result => result.value); | |
} |
async function someFunc () { | |
// since we’re using await on someAsyncThing and the promise rejected | |
// this line will now throw it will throw `new Error('Boom')` | |
const result = await someAsyncThing(); | |
// this line will not execute | |
return result.value; | |
} | |
// externally we’ll get a rejected promise returned containing `Error('Boom')` | |
await someFunc(); | |
// But since we’re using await here, the rejected promise gets turned back |
function fetchStuff(data) { | |
const page = data.page; | |
return fetchResults(page) | |
.then(res => res.results); | |
} | |
fetchStuff() | |
.catch(err => { /* handle error here */ }); |
async function fetchStuff(data) { | |
const page = data.page; | |
const results = await fetchResults(page); | |
return res.results; | |
} | |
fetchStuff() | |
.catch(err => { /* handle error here */ }); |
function fetchStuff(data) { | |
try { | |
const page = data.page; | |
return fetchResults(page) | |
.then(res => res.results); | |
} catch (err) { | |
return Promise.reject(err); | |
} | |
} |