Last active
February 18, 2019 08:16
-
-
Save leny/e57c06f894f6606385398f101603d5fa to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/zakigis
This file contains hidden or 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
const randomWait = (delay) => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (Math.round(Math.random() * 2) % 2) { | |
resolve("ok"); | |
} else { | |
reject(new Error("wrong!")); | |
} | |
}, delay * 1000); | |
}); | |
const main = async () => { | |
try { | |
const results = []; | |
results.push(await randomWait(1)); | |
console.log(results); | |
results.push(await randomWait(1)); | |
console.log(results); | |
} catch(error) { | |
console.log(error.message); | |
} | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment