Last active
June 2, 2017 05:44
-
-
Save kavunshiva/856bde09fc1137b82a5e9bc5e215ec81 to your computer and use it in GitHub Desktop.
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
let someBoringPromise = new Promise((winner, loser) => winner()) | |
let anotherBoringPromise = new Promise((winner, loser) => loser()) | |
let someLessBoringPromise = new Promise((winner, loser) => winner(console.log("cat"))) | |
let anotherLessBoringPromise = new Promise((winner, loser) => loser(console.log("dog"))) | |
let someBoringPromiseWithPotential = new Promise((winner, loser) => winner("cat")) | |
someBoringPromiseWithPotential.then((value) => console.log(`${value}s are cool, i guess`)) | |
someBoringPromiseWithPotential.then((thing) => (thing)) | |
.then((stuff) => { | |
const otherThing = `${stuff}s${stuff}s${stuff}s` | |
console.log(otherThing) | |
return otherThing | |
}) | |
.then((dog) => (dog.length)) | |
.then((num) => {`${num} cats: so many!`; return num}) | |
.then((whatever) => console.log(`${whatever}. whoa.`)) | |
someBoringPromiseWithPotential.then((thing) => (thing)) | |
.then((stuff) => { | |
const otherThing = `${stuff}s${stuff}s${stuff}s` | |
console.log(otherThing) | |
return otherThing | |
}) | |
.then((glug) => iSeeGodAndTheUniverseAndEverything) | |
.then((dog) => (dog.length)) | |
.then((num) => {`${num} cats: so many!`; return num}) | |
.then((whatever) => console.log(`${whatever}. whoa.`)) | |
.catch(() => console.log("oh, uh, whoops")) | |
let barkingPromise = new Promise((success, failure) => { | |
setTimeout(() => success(console.log("bark")), 5000) | |
}) | |
[ | |
setTimeout(() => console.log("Promises"), 5000), | |
setTimeout(() => console.log("are"), 3000), | |
setTimeout(() => console.log("cool"), 3000) | |
] | |
Promise.all([ | |
new Promise((resolve, reject) => { | |
setTimeout(() => resolve("Promises"), 5000) | |
}), | |
new Promise((resolve, reject) => { | |
setTimeout(() => resolve("are"), 3000) | |
}), | |
new Promise((resolve, reject) => { | |
setTimeout(() => resolve("cool"), 3000) | |
}) | |
]).then((words) => words.forEach((word) => console.log(word))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment