Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function fakeAsyncCall(resultText = 'foo data') {
  2. return new Promise((resolve, reject) => {
  3. if (typeof resultText !== 'string') {
  4. return reject('result text should equal string');
  5. }
  6. setTimeout(() => { resolve(resultText) }, 1000);
  7. });
  8. }
  9.  
  10. async function getData() {
  11. try {
  12. const f1 = await fakeAsyncCall();
  13. const f2 = await fakeAsyncCall();
  14. const f3 = await fakeAsyncCall();
  15. const f4 = await fakeAsyncCall(2);
  16.  
  17. console.log(f1, f2, f3, f4); // 'foo data' x 4
  18.  
  19. } catch (error) {
  20. console.error(`Uh oh: ${error}`);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement