It is possible to use await with an expression that does not evaluate to a promise. Whether that is useful, is questionable.
First of all, when await is followed by an expression that does not evaluate to a promise object, it is turned into one -- a resolved promise.
The main difference you get by using await with a non-promise or a resolved promise, is that await will make the async function return. This behaviour is not dependent on whether the promise is already resolved or not. await always postpones the further execution of the function by placing that resuming-job on the promise job queue.
See the difference here:
async function test() { let a = 1; // Without await console.log(a); return 2; } test().then(console.log); console.log("end of main, synchronous code");
And with await
async function test() { let a = await 1; // With await console.log(a); return 2; } test().then(console.log); console.log("end of main, synchronous code");
Note the different order of execution.
cannotFailfunction contains an async code that is callback-based, you can wrap a promise around it and return that promise from thecannotFailfunction.