Last active
June 13, 2017 14:25
-
-
Save gskachkov/f118241bec91edada49f784e99756dd8 to your computer and use it in GitHub Desktop.
async method in class
This file contains hidden or 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
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