summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2019-05-19 17:17:29 -0700
committerGitHub <noreply@github.com>2019-05-19 17:17:29 -0700
commit667e71760e7f2dd558e868796bd6e6008a3bac16 (patch)
treedc700c791438f49eea5e2d2aff2737e7a5442f0f
parent4330d536c106592139fa82062494c9dba0da1fdb (diff)
downloadasync-667e71760e7f2dd558e868796bd6e6008a3bac16.tar.gz
BREAKING CHANGE: remove partial application feature of applyEach (#1640)
* BREAKING CHANGE: remove partial application feature of applyEach * add awaitable tests for applyEach
-rw-r--r--lib/eachSeries.js2
-rw-r--r--lib/internal/applyEach.js13
-rw-r--r--test/applyEach.js39
-rw-r--r--test/es2017/asyncFunctions.js4
-rw-r--r--test/es2017/awaitableFunctions.js17
-rw-r--r--test/priorityQueue.js12
6 files changed, 34 insertions, 53 deletions
diff --git a/lib/eachSeries.js b/lib/eachSeries.js
index a23aef5..3831456 100644
--- a/lib/eachSeries.js
+++ b/lib/eachSeries.js
@@ -6,7 +6,7 @@ import awaitify from './internal/awaitify'
*
* Note, that unlike [`each`]{@link module:Collections.each}, this function applies iteratee to each item
* in series and therefore the iteratee functions will complete in order.
-
+
* @name eachSeries
* @static
* @memberOf module:Collections
diff --git a/lib/internal/applyEach.js b/lib/internal/applyEach.js
index f95d8ac..c08a5eb 100644
--- a/lib/internal/applyEach.js
+++ b/lib/internal/applyEach.js
@@ -1,17 +1,14 @@
-import initialParams from './initialParams';
import wrapAsync from './wrapAsync';
+import awaitify from './awaitify'
-export default function applyEach(eachfn) {
- return function(fns, ...callArgs) {
- var go = initialParams(function(args, callback) {
+export default function (eachfn) {
+ return function applyEach(fns, ...callArgs) {
+ const go = awaitify(function (callback) {
var that = this;
return eachfn(fns, (fn, cb) => {
- wrapAsync(fn).apply(that, args.concat(cb));
+ wrapAsync(fn).apply(that, callArgs.concat(cb));
}, callback);
});
- if (callArgs.length) {
- return go.apply(this, callArgs);
- }
return go;
};
}
diff --git a/test/applyEach.js b/test/applyEach.js
index 4a67ee4..a5fce95 100644
--- a/test/applyEach.js
+++ b/test/applyEach.js
@@ -27,7 +27,7 @@ describe('applyEach', () => {
cb(null, 3);
}, 18);
};
- async.applyEach([one, two, three], 5, (err, results) => {
+ async.applyEach([one, two, three], 5)((err, results) => {
assert(err === null, err + " passed instead of 'null'");
expect(call_order).to.eql(['two', 'one', 'three']);
expect(results).to.eql([1, 2, 3]);
@@ -51,7 +51,7 @@ describe('applyEach', () => {
throw new Error('third task - should not get here');
}
- async.applyEach({one, two, three}, 5, () => {
+ async.applyEach({one, two, three}, 5)(() => {
throw new Error('final callback - should not get here');
});
@@ -84,7 +84,7 @@ describe('applyEach', () => {
cb(null, 3);
}, 15);
}
- async.applyEachSeries([one, two, three], 5, (err, results) => {
+ async.applyEachSeries([one, two, three], 5)((err, results) => {
assert(err === null, err + " passed instead of 'null'");
expect(call_order).to.eql(['one', 'two', 'three']);
expect(results).to.eql([1, 2, 3]);
@@ -109,7 +109,7 @@ describe('applyEach', () => {
function three(/*, cb */) {
throw new Error('third task - should not get here');
}
- async.applyEachSeries([one, two, three], 5, () => {
+ async.applyEachSeries([one, two, three], 5)(() => {
throw new Error('final callback - should not get here');
});
@@ -118,35 +118,4 @@ describe('applyEach', () => {
done();
}, 25);
});
-
- it('applyEach partial application', (done) => {
- var call_order = [];
- var one = function (val, cb) {
- expect(val).to.equal(5);
- setTimeout(() => {
- call_order.push('one');
- cb(null, 1);
- }, 10);
- };
- var two = function (val, cb) {
- expect(val).to.equal(5);
- setTimeout(() => {
- call_order.push('two');
- cb(null, 2);
- }, 5);
- };
- var three = function (val, cb) {
- expect(val).to.equal(5);
- setTimeout(() => {
- call_order.push('three');
- cb(null, 3);
- }, 15);
- };
- async.applyEach([one, two, three])(5, (err, results) => {
- if (err) throw err;
- expect(call_order).to.eql(['two', 'one', 'three']);
- expect(results).to.eql([1, 2, 3]);
- done();
- });
- });
});
diff --git a/test/es2017/asyncFunctions.js b/test/es2017/asyncFunctions.js
index efb6555..553b7f4 100644
--- a/test/es2017/asyncFunctions.js
+++ b/test/es2017/asyncFunctions.js
@@ -272,14 +272,14 @@ module.exports = function () {
*/
it('should handle async functions in applyEach', (done) => {
- async.applyEach([asyncIdentity, asyncIdentity])(input, (err, result) => {
+ async.applyEach([asyncIdentity, asyncIdentity], input)((err, result) => {
expect(result).to.eql([input, input]);
done(err);
});
});
it('should handle async functions in applyEachSeries', (done) => {
- async.applyEachSeries([asyncIdentity, asyncIdentity])(input, (err, result) => {
+ async.applyEachSeries([asyncIdentity, asyncIdentity], input)((err, result) => {
expect(result).to.eql([input, input]);
done(err);
});
diff --git a/test/es2017/awaitableFunctions.js b/test/es2017/awaitableFunctions.js
index b45b56c..55bcc9e 100644
--- a/test/es2017/awaitableFunctions.js
+++ b/test/es2017/awaitableFunctions.js
@@ -316,7 +316,22 @@ module.exports = function () {
* Control flow
*/
- // TODO: figure out to do with applyEach
+ it('should return a Promise: applyEach', async () => {
+ const calls = []
+ await async.applyEach([
+ async (v, x) => { calls.push(v, x) },
+ async (v, x) => { calls.push(v, x) }
+ ], 5, 6)();
+ expect(calls).to.eql([5, 6, 5, 6])
+ })
+ it('should return a Promise: applyEachSeries', async () => {
+ const calls = []
+ await async.applyEachSeries([
+ async (v, x) => { calls.push(v, x) },
+ async (v, x) => { calls.push(v, x) }
+ ], 5, 6)();
+ expect(calls).to.eql([5, 6, 5, 6])
+ })
it('should return a Promise: auto', async () => {
expect (async.auto.name).to.contain('auto')
diff --git a/test/priorityQueue.js b/test/priorityQueue.js
index 1a8cc76..c3ece02 100644
--- a/test/priorityQueue.js
+++ b/test/priorityQueue.js
@@ -239,7 +239,7 @@ describe('priorityQueue', () => {
q.push('foo4', 1, () => {calls.push('foo4 cb');});
});
});
-
+
it('should not call the drain callback if receives empty push and tasks are still pending', (done) => {
var call_order = [];
@@ -247,21 +247,21 @@ describe('priorityQueue', () => {
call_order.push('process ' + task);
callback('error', 'arg');
}, 1);
-
+
q.push(1, 1, (err, arg) => {
expect(err).to.equal('error');
expect(arg).to.equal('arg');
call_order.push('callback ' + 1);
});
-
+
q.push(2, 1, (err, arg) => {
expect(err).to.equal('error');
expect(arg).to.equal('arg');
call_order.push('callback ' + 2);
});
-
+
expect(q.length()).to.equal(2);
-
+
q.drain = function () {
expect(call_order).to.eql([
'process 1', 'callback 1',
@@ -272,7 +272,7 @@ describe('priorityQueue', () => {
expect(q.running()).to.equal(0);
done();
};
-
+
q.push([], 1, () => {});
});
});