Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Last active June 13, 2017 14:25
Show Gist options
  • Save gskachkov/f118241bec91edada49f784e99756dd8 to your computer and use it in GitHub Desktop.
Save gskachkov/f118241bec91edada49f784e99756dd8 to your computer and use it in GitHub Desktop.
async method in class
async function foo(value) {
// Return async result async
return new Promise(resolve => {
setTimeout(() => resolve(value), 100);
});
}
class SuperClass {
async getValue(value) {
var result = await foo(value);
return this.value + ' ' + result;
}
}
class BaseClass extends SuperClass {
constructor(value) {
var asyncWrapperForSuper = async () => {
super();
this.value = await Promise.resolve('any-value');
};
asyncWrapperForSuper();
}
}
const obj = new BaseClass();
obj.getValue('boo').then(result => console.log(result)); // any-value boo
obj.async(); // usual function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment