Skip to content

Instantly share code, notes, and snippets.

@Kamisama666
Kamisama666 / mapAll.js
Created May 8, 2017 10:20
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);
@Kamisama666
Kamisama666 / pq.js
Last active April 20, 2017 11:37
Takes a native javascript promise and returns a Q promise
const Q = require('q');
/**
* Transforms a Promise to a Q promise
* @param {Promise} promise
* @return {Q}
*/
function pq(promise) {
const deferred = Q.defer();