Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement