summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2019-05-18 20:52:45 -0700
committerAlexander Early <alexander.early@gmail.com>2019-05-18 20:52:45 -0700
commit562bd495d18a1f2a96255d8e6c7d284edae5ec39 (patch)
tree101c1ffb9a4f5a0f43139cc33bc3d42c113ea8ce
parent4330d536c106592139fa82062494c9dba0da1fdb (diff)
downloadasync-applyeach-no-partial.tar.gz
BREAKING CHANGE: remove partial application feature of applyEachapplyeach-no-partial
-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/priorityQueue.js12
5 files changed, 18 insertions, 52 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/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, () => {});
});
});