Created
July 17, 2017 12:35
-
-
Save johnstew/fc8f6ca38f5757d1ec53fdd9d8a2601e to your computer and use it in GitHub Desktop.
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
class Foo { | |
async getData() { | |
try { | |
const f1 = await this.fakeAsyncCall(); | |
const f2 = await this.fakeAsyncCall(); | |
const f3 = await this.fakeAsyncCall(); | |
const f4 = await this.fakeAsyncCall(); | |
console.log(f1, f2, f3, f4); // 'foo data' x 4 | |
} catch (error) { | |
console.error(`Uh oh: ${error}`); | |
} | |
} | |
fakeAsyncCall(resultText = 'foo data') { | |
return new Promise((resolve, reject) => { | |
if (typeof resultText !== 'string') { | |
return reject('result text should equal string'); | |
} | |
setTimeout(() => { resolve(resultText) }, 1000); | |
}); | |
} | |
} | |
new Foo().getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment