there is no await on top-level allowed and my expectation was that the error thrown below would be logged as warning only but it turns out to be a blocker for completion, i.e. upon statement await fsProm.stat
the processing basically stops. I would not understand why?
const fsProm = require('fs').promises;
async function codeWithUnhandledPromise(){
const notAwaited = Promise.resolve().then(function(){
throw new Error('Irrelevant');
});
await fsProm.stat( __filename );
console.log( 'Not reached' );
}
async function main(){
try {
await codeWithUnhandledPromise();
} catch (error) {
console.log( 'Not reached' );
} finally {
console.log( 'Not Reached' );
}
}
main().then(undefined,function(){
console.log( 'Not Reached' );
return;
});
console.log( 'done' );
2