creating own promise1

 let cart=["shoes","pants","kurtas"];

const promise=createOrder(cart);
console.log(promise);

promise.then((res)=>{
    console.log(res);
    //promise channing
   
})
.catch(err=>{
 console.log(err);

})
   
//start api which is running to order creation:---
function createOrder(cart){
    const mypromise=new  Promise(function(resolve,reject){
        if(!validiteCart(cart)){
            const err=new Error('cart is not valid');
            reject (err);
        }
        const orderId='123';
        if(orderId){
            // resolve (orderId);
            setTimeout(() => {
                console.log(orderId);
            },5000);
        }
    })
    return mypromise;
}

// function proceedToPayment(orderId){
//     //we will to do payment
//     return new Promise((resolve,reject)=>{
//         resolve("payment successfull");
//     });
// }
//end api which is running to order creation:--
//proceed to payment api:--

//end of proceed to payment api"--

function validiteCart(cart){
    return true;
    // return false;
}

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation