diff --git a/promiseFns/any.js b/promiseFns/any.js index 11e7922..5eeef5b 100644 --- a/promiseFns/any.js +++ b/promiseFns/any.js @@ -1,5 +1,8 @@ module.exports = (Bluebird) => { - Bluebird.any = (prom, n) => Bluebird.resolve(prom).any(); + Bluebird.any = (prom, n) => Bluebird.resolve((async () => + Bluebird.resolve(prom).any() + )()); + Bluebird.prototype.any = async function() { // const items = await this; // if(items.length === 0) { throw new TypeError("0 promises passed to any")} diff --git a/promiseFns/filter.js b/promiseFns/filter.js index 14492a7..22b5b7a 100644 --- a/promiseFns/filter.js +++ b/promiseFns/filter.js @@ -1,6 +1,9 @@ const util = require("./util"); module.exports = (Bluebird) => { - Bluebird.filter = (x, predicate, opts) => Bluebird.resolve(x).filter(predicate, opts); + Bluebird.filter = (x, predicate, opts) => Bluebird.resolve((async () => + Bluebird.resolve(x).filter(predicate, opts) + )()); + Bluebird.prototype.filter = async function(predicate, {concurrency} = {}) { const values = await this.all(); const predicateResults = await this.map(predicate, {concurrency}); diff --git a/promiseFns/map.js b/promiseFns/map.js index d2121d8..b9a44e6 100644 --- a/promiseFns/map.js +++ b/promiseFns/map.js @@ -1,6 +1,8 @@ const util = require("./util"); module.exports = (Bluebird) => { - Bluebird.map = (x, mapper, opts) => Bluebird.resolve(x).map(mapper, opts); + Bluebird.map = (x, mapper, opts) => Bluebird.resolve((async () => + Bluebird.resolve(x).map(mapper, opts) + )()); Bluebird.prototype.map = async function(mapper, {concurrency} = {}) { const values = await Bluebird.all(await this); diff --git a/tests/any.js b/tests/any.js index 25931e8..900cc58 100644 --- a/tests/any.js +++ b/tests/any.js @@ -37,7 +37,6 @@ describe("any", () => { ]); assert.equal(v, 2); }); - it("resolves with two rejections and a resolve ordered", async () => { const v = await Promise.any([ @@ -56,4 +55,22 @@ describe("any", () => { ]); assert.equal(v, 2); }); + + it('any should return bluebird promise', () => { + const v = Promise.any([ + Promise.reject(0), + Promise.reject(1), + Promise.resolve(2) + ]); + assert.ok(v instanceof Promise) + }) + + it('prototype.any should not return bluebird promise', () => { + const v = Promise.prototype.any([ + Promise.reject(0), + Promise.reject(1), + Promise.resolve(2) + ]); + assert.equal(v instanceof Promise, false) + }) }); \ No newline at end of file diff --git a/tests/filter.js b/tests/filter.js index fc651e2..9233c0e 100644 --- a/tests/filter.js +++ b/tests/filter.js @@ -29,6 +29,16 @@ describe("filter", () => { }); assert.deepEqual(arr, [2]); }); + + it('filter should return bluebird promise', () => { + const arr = Promise.filter([1,2,3], x => x) + assert.ok(arr instanceof Promise) + }) + + it('prototype.filter should not return bluebird promise', () => { + const arr = Promise.prototype.filter([1,2,3], x => x) + assert.equal(arr instanceof Promise, false) + }) }); const specify = it; diff --git a/tests/map.js b/tests/map.js index 25ac5c3..aeec35a 100644 --- a/tests/map.js +++ b/tests/map.js @@ -29,6 +29,16 @@ describe("map", () => { }); assert.deepEqual(arr, [2,3,4]); }); + + it('map should return bluebird promise', () => { + const arr = Promise.map([1,2,3], x => x) + assert.ok(arr instanceof Promise) + }) + + it('prototype.map should not return bluebird promise', () => { + const arr = Promise.prototype.map([1,2,3], x => x) + assert.equal(arr instanceof Promise, false) + }) }); const specify = it;