This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myAsyncFunction() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const randomNumber = Math.random(); | |
if (randomNumber > 0.5) { | |
resolve(randomNumber); // Resolve the promise with a value | |
} else { | |
reject(new Error("Random number is less than 0.5")); // Reject the promise with an error | |
} | |
}, 1000); |