<!--
title: prefer async/await patterns
domain: app-frameworks
topic: Concurrency
language: JavaScript
source: discourse/discourse
updated: 2025-06-25
url: https://awesomereviewers.com/reviewers/discourse-prefer-asyncawait-patterns/
-->

Convert promise chains to async/await syntax for better readability, error handling, and proper cleanup operation placement. Async functions automatically return promises, so avoid redundant Promise.resolve() calls or manual promise wrapping.

Key benefits:
- Cleaner error handling with try/catch blocks
- Proper placement of finally blocks that wrap entire operations
- Elimination of unnecessary promise constructors

Example transformation:
```javascript
// Before: Complex promise chain with misplaced finally
destroy(deletedBy, opts) {
  return this.setDeletedState(deletedBy).then(() => {
    // operation
  }).finally(() => {
    // cleanup only applies to inner promise
  });
}

// After: Clean async/await with proper cleanup scope
async destroy(deletedBy, opts) {
  this.set("isDeleting", true);
  try {
    await this.setDeletedState(deletedBy);
    // operation
  } finally {
    // cleanup applies to entire operation
    this.set("isDeleting", false);
  }
}
```

Avoid returning Promise.resolve() from async functions as they already return promises automatically.
