Created
July 17, 2017 12:26
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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