Skip to content

Instantly share code, notes, and snippets.

@johnstew
Created July 17, 2017 12:35
Show Gist options
  • Save johnstew/fc8f6ca38f5757d1ec53fdd9d8a2601e to your computer and use it in GitHub Desktop.
Save johnstew/fc8f6ca38f5757d1ec53fdd9d8a2601e to your computer and use it in GitHub Desktop.
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