Course contentsShow
← JavaScript
Lesson 1393 of 2,72330. Async/AwaitFree lesson

Creating Promises Unnecessarily

Recognize the antipattern of wrapping async/await logic in 'new Promise' when it's already Promise-based.

Creating Promises Unnecessarily

What you'll learn: You'll recognize and avoid the common antipattern of wrapping async/await logic in new Promise() when it's already Promise-based.

The Redundant Wrapper Problem

When you use async/await, your function already returns a Promise automatically. Yet developers sometimes wrap their async logic in new Promise(), creating an unnecessary extra layer.

The antipattern looks like this:

// ❌ ANTIPATTERN: Wrapping async/await in new Promise
function fetchUser(id) {
  return new Promise(async (resolve, reject) => {
    try {
      const response = await fetch(`/users/${id}`);
      const data = await response.json();
      resolve(data);
    } catch (error) {
      reject(error);
    }
  });
}

Why this is wrong: The async function inside the executor already returns a Promise. You're creating a Promise that contains another Promise, adding complexity and defeating the purpose of async/await's cleaner syntax.

The Clean Approach

Simply use async directly:

// ✅ CORRECT: Just use async
async function fetchUser(id) {
  const response = await fetch(`/users/${id}`);
  const data = await response.json();
  return data;
  // Errors automatically reject the returned Promise
}

Why This Happens

Developers coming from callback-based code sometimes think they need new Promise() to "promisify" something. But async functions handle this automatically—returning values resolves the Promise, and thrown errors reject it.

Think of it this way: Using new Promise() with async/await is like putting a letter in an envelope, then putting that envelope in another envelope to mail it. The outer envelope serves no purpose.

Key Takeaway: Never wrap async/await logic in new Promise(). Async functions already return Promises, so the wrapper is redundant and adds unnecessary complexity.