JSFiddle - React, Tailwind, and code Playground

by Kabir Hossain

JavaScript

function test() {
	return new Promise( (resolve, reject) => {
  	if( Math.round( Math.random() ) ) {
    //	resolve("okay")
    	setTimeout( () => {
      	resolve("okay")
      }, 5000 )
    } else {
    
     setTimeout( () => {
      	reject("Not Okay")
      }, 4000 )

    } 
  })
}

function test2() {
	return test()
  	.then(resp => {
    	return test()
      	.then(respx => respx)
      	.catch(error => {
        	throw new Error(error);
        })
    })
    .then(resp => resp)
  	.catch(error => {
      throw new Error(error);
    })
}

( async () => {

	try {
/* 
    test2()
      .then(resp => {
        console.log({resp});
      })
      .catch(error => {
        console.error("xyz : ", error);
      }) */
      

    const dt = await test2();
    console.log({dt})
    console.log("hello world!");
      
  } catch(error) {
  	console.error("test2 error : ", error);
  }

})();
/* 
const result = new Array(100000);

for(let i=0; i<result.length; i++) {
  ( async() => {
    await someAsync(result[i]);
  })()
}

Promise.all(
  result.map( r => someAsync(r))
)
.then(resp => {

})
.catch(error => {
console.error(error);
})

result.forEach()
result.map()

result.reduce()
result.filter()
result.find()

 */