Directly return a promise when the value is intended to be used by the caller. For example, promise of query result can be directly returned.
await should be used for commands to ensure
void is returned. The reason why
void is returned for command is to enforce command-query separation. Do not mix updates with reads as that violates single-responsibility principle.
await is required for the
catch block to work. Without the
await, the error will bubble up to the caller without the
await all promises. Sometime a promise should be a side-effect to prevent blocking the
async function or causing the entire
async function to be rejected when the promise fails.
Did you know all these scenarios? We’d like to talk to you! Battlefy is hiring.