Skip to content

Instantly share code, notes, and snippets.

@johndaley-me
Last active July 23, 2017 02:21
Show Gist options
  • Save johndaley-me/5a23f6c5366e5d349bbfdd686b3c8cf8 to your computer and use it in GitHub Desktop.
Save johndaley-me/5a23f6c5366e5d349bbfdd686b3c8cf8 to your computer and use it in GitHub Desktop.
Promises only
function findFooById(id) {
// pretend this is a DB query or something asynchronous
return Promise.resolve({
id,
name: 'Foo'
});
}
function findFoo1() {
console.log('finding foo 1');
return findFooById(1);
}
function findFoo2() {
console.log('finding foo 2');
return findFooById(2);
}
export default function () {
return Promise.all([
findFoo1(),
findFoo2()
]);
}
// Console output:
// finding foo 1
// finding foo 2
// [{"id":1,"name":"Foo"},{"id":2,"name":"Foo"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment