My understanding of async/await
is fairly simplistic: if you await
functions which return a promise they will return the value passed into the resolve
callback. A function containing an await
keyword must be marked async
. If that isn't true, that's where my understanding is faulty.
Either I'm being super-unobservant, or the following behaviour proves my understanding to be incorrect:
async function mySynchroniser(promise) {
return await promise;
}
const stuff = mySynchroniser(new Promise(function (resolve) {
resolve('stuff');
}));
console.log(stuff);
I would expect the output to be stuff
, but the actual output is Promise {<pending>}
. When I expand the Promise in the console log, it has resolved to the value 'stuff', which should surprise nobody.
Please help me find the flaw in my understanding or observational skills.