Skip to content

Instantly share code, notes, and snippets.

@Gaafar
Created May 19, 2019 09:27
Show Gist options
  • Save Gaafar/d5a5a6eee610bd6342c5724b833e3539 to your computer and use it in GitHub Desktop.
Save Gaafar/d5a5a6eee610bd6342c5724b833e3539 to your computer and use it in GitHub Desktop.
promise-utils
// 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