Last active
May 14, 2017 00:35
-
-
Save NigelEarle/fdd9a9905bbeeec2cd33fe1656d1e5e5 to your computer and use it in GitHub Desktop.
Passing resolve along from chained Promises
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
const cleanRoom = () => { | |
return new Promise((resolve, reject) => { | |
resolve('Clean room,'); | |
}); | |
} | |
const takeTrash = (message) => { | |
return new Promise((resolve, reject) => { | |
resolve(message + ' Take out trash,'); | |
}) | |
} | |
const getIceCream = (message) => { | |
return new Promise((resolve, reject) => { | |
resolve(message + ' Get Ice cream'); | |
}) | |
} | |
cleanRoom() | |
.then((result) => { | |
return takeTrash(result); | |
}) | |
.then((result) => { | |
return getIceCream(result); | |
}) | |
.then((result) => { | |
console.log(result) | |
}) | |
// Only using resolve() | |
const cleanRoom = () => Promise.resolve('Clean Room,') | |
const takeTrash = (message) => Promise.resolve(message + ' Take Trash,') | |
const getIceCream = (message) => Promise.resolve(message + ' Get Ice Cream') | |
cleanRoom() | |
.then((result) => { | |
return takeTrash(result); | |
}) | |
.then((result) => { | |
return getIceCream(result); | |
}) | |
.then((result) => { | |
console.log(result) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment