Skip to content

Instantly share code, notes, and snippets.

@Kamisama666
Created May 8, 2017 10:20
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 Kamisama666/400a1eda96e945f3262d0a1b190bc2c1 to your computer and use it in GitHub Desktop.
Save Kamisama666/400a1eda96e945f3262d0a1b190bc2c1 to your computer and use it in GitHub Desktop.
Maps a function that returns a promise and then passes that array of promises to Q.all so they are all processed. Uses Fn.js and Q. Example included
"use strict";
const Q = require('q');
const fn = require('fn.js');
// Maps a function that returns a promise and then passes that array of promises to Q.all so they are all processed
const mapAll = fn.curry(fn.compose(Q.all, fn.map), 2);
// Returns a promise
function returnPromise(something) {
return Q().then(() => something);
}
const somethings = [1, 2, 3];
// Example of use
Q()
.then(function() {
return somethings;
})
.then(mapAll(returnPromise))
.then(function(result) {
console.log(result)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment