Skip to content

Instantly share code, notes, and snippets.

@NigelEarle
Last active May 14, 2017 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NigelEarle/fdd9a9905bbeeec2cd33fe1656d1e5e5 to your computer and use it in GitHub Desktop.
Save NigelEarle/fdd9a9905bbeeec2cd33fe1656d1e5e5 to your computer and use it in GitHub Desktop.
Passing resolve along from chained Promises
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