Created
September 22, 2019 06:57
-
-
Save detoner777/448fc53e5e6229e4cae40aa2ccae7ec7 to your computer and use it in GitHub Desktop.
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
console.log("Request data..."); | |
// setTimeout(() => { | |
// console.log("Preparing data..."); | |
// const backendData = { | |
// server: "aws", | |
// port: 2000, | |
// status: "working" | |
// }; | |
// setTimeout(() => { | |
// backendData.modifed = true; | |
// console.log("Data received", backendData); | |
// }, 2000); | |
// }, 2000); | |
// const p = new Promise((resolve, reject) => { | |
// setTimeout(() => { | |
// console.log("Preparing data..."); | |
// const backendData = { | |
// server: "aws", | |
// port: 2000, | |
// status: "working" | |
// }; | |
// resolve(backendData); | |
// }, 2000); | |
// }); | |
// p.then(data => { | |
// return new Promise((resolve, reject) => { | |
// setTimeout(() => { | |
// data.modified = true; | |
// resolve(data); | |
// }, 2000); | |
// }); | |
// }) | |
// .then(clientData => { | |
// clientData.fromPromise = true; | |
// return clientData; | |
// }) | |
// .then(data => { | |
// console.log("Modified", data); | |
// }) | |
// .catch(err => console.error("Error", err)) | |
// .finally(() => console.log("finally")); | |
const sleep = ms => { | |
return new Promise(resolve => { | |
setTimeout(() => resolve(), ms); | |
}); | |
}; | |
// sleep(2000).then(() => console.log("After 2 sec")); | |
// sleep(3000).then(() => console.log("After 3 sec")); | |
Promise.all([sleep(2000), sleep(5000)]).then(() => { | |
console.log("All promises"); | |
}); | |
Promise.race([sleep(2000), sleep(5000)]).then(() => { | |
console.log("Race promises"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment