const ret = () => new Promise(resolve => setTimeout( () => resolve('somestring'), 1000));
async function wrapper() {
let someString = await ret();
return someString;
}
console.log( wrapper() );
It logs Promise { <pending> }
;
Why does it return a Promise instead of 'somestring'
?
I'm using the Babel ES7 preset to compile this.
console.log(someString)
inside of thewrapper()
function or inside of any otherasync
function, you will get thesomestring
value. – AcatalecticsomeString
right after awaiting it output the correct value? – Sudsawait
for it. The result of async function execution is always a promise. You can await for it if you're inside another async function or unwrap the result with.then(...)
if you're not. – Calcificasync/await
is not part of ES7. – Headwind