Skip to content

Files

Latest commit

 

History

History
28 lines (21 loc) · 569 Bytes

prefer-await-to-then.md

File metadata and controls

28 lines (21 loc) · 569 Bytes

Pattern: Use of Promise.then() chains

Issue: -

Description

The async/await syntax provides a more readable way to handle promises compared to chaining .then(), .catch(), and .finally() methods. Using await makes asynchronous code appear more linear and easier to understand.

Examples

Example of incorrect code:

function foo() {
  hey.then((x) => {});
}

// With { strict: true }
async function hi() {
  await thing().then((x) => {});
}

Example of correct code:

async function hi() {
  await thing();
}