Last active
July 23, 2017 02:21
-
-
Save johndaley-me/5a23f6c5366e5d349bbfdd686b3c8cf8 to your computer and use it in GitHub Desktop.
Promises only
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
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