Dealing with the Callback Hell situation using Promise. Exploring the different ways of creating and using promise in executing the asynchronous task.

PHOTO EMBED

Wed Apr 23 2025 01:17:39 GMT+0000 (Coordinated Universal Time)

Saved by @signup

function stepPromise(stepName) {
    return new Promise((resolve) => {
        setTimeout(() => {
            console.log(`${stepName} completed`);
            resolve();
        }, 1000);
    });
}

// Promise chaining to avoid callback hell
stepPromise("Step 1")
    .then(() => stepPromise("Step 2"))
    .then(() => stepPromise("Step 3"))
    .then(() => console.log("All steps completed (with Promise)"));
content_copyCOPY

https://chatgpt.com/share/6806eb90-bdac-800e-8a25-6ffb72f6bc0e