Skip to content

Instantly share code, notes, and snippets.

@johnstew
Created July 17, 2017 12:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johnstew/f843b971b6c307f5fae467ca4bb6d0a6 to your computer and use it in GitHub Desktop.
function fakeAsyncCall(resultText = 'foo data') {
return new Promise((resolve, reject) => {
if (typeof resultText !== 'string') {
return reject('result text should equal string');
}
setTimeout(() => { resolve(resultText) }, 1000);
});
}
async function getData() {
try {
const f1 = await fakeAsyncCall();
const f2 = await fakeAsyncCall();
const f3 = await fakeAsyncCall();
const f4 = await fakeAsyncCall(2);
console.log(f1, f2, f3, f4); // 'foo data' x 4
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment