Created
May 19, 2019 09:27
-
-
Save Gaafar/d5a5a6eee610bd6342c5724b833e3539 to your computer and use it in GitHub Desktop.
promise-utils
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
// version 1: using promise with utility functions | |
const passthrough = fn => data => Promise.all([data, fn(data)]) | |
const spread = fn => list => fn(...list) | |
const makeRequest = () => promise1() | |
.then(passthrough(promise2)) | |
.then(spread(promise3)) | |
// version 2: async/await | |
const makeRequest = async () => { | |
const value1 = await promise1() | |
const value2 = await promise2(value1) | |
return promise3(value1, value2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment