Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.