Skip to content

Instantly share code, notes, and snippets.

@leny
Last active February 18, 2019 08:16
Show Gist options
  • Save leny/e57c06f894f6606385398f101603d5fa to your computer and use it in GitHub Desktop.
Save leny/e57c06f894f6606385398f101603d5fa to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/zakigis
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