summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2016-07-09 18:52:17 -0700
committerAlexander Early <alexander.early@gmail.com>2016-07-09 18:52:17 -0700
commitd2764c298216d3096523d986804dd0718e2a52e2 (patch)
tree7c3d25defba9808a092e12b4c81b1a51893a20f0
parenta16b450c182199a5b268662af64478060a5bfa97 (diff)
downloadasync-d2764c298216d3096523d986804dd0718e2a52e2.tar.gz
wrap callbacks in onlyOnce
-rw-r--r--lib/doDuring.js3
-rw-r--r--lib/doWhilst.js4
-rw-r--r--lib/during.js3
-rw-r--r--lib/whilst.js4
4 files changed, 10 insertions, 4 deletions
diff --git a/lib/doDuring.js b/lib/doDuring.js
index 14a5ae1..c536f30 100644
--- a/lib/doDuring.js
+++ b/lib/doDuring.js
@@ -1,5 +1,6 @@
import noop from 'lodash/noop';
import rest from 'lodash/rest';
+import onlyOnce from './internal/onlyOnce';
/**
* The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
@@ -23,7 +24,7 @@ import rest from 'lodash/rest';
* will be passed an error if one occured, otherwise `null`.
*/
export default function doDuring(fn, test, callback) {
- callback = callback || noop;
+ callback = onlyOnce(callback || noop);
var next = rest(function(err, args) {
if (err) return callback(err);
diff --git a/lib/doWhilst.js b/lib/doWhilst.js
index 163c6a9..ee8f12a 100644
--- a/lib/doWhilst.js
+++ b/lib/doWhilst.js
@@ -1,6 +1,8 @@
import noop from 'lodash/noop';
import rest from 'lodash/rest';
+import onlyOnce from './internal/onlyOnce';
+
/**
* The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
* the order of operations, the arguments `test` and `iteratee` are switched.
@@ -25,7 +27,7 @@ import rest from 'lodash/rest';
* `iteratee`'s callback. Invoked with (err, [results]);
*/
export default function doWhilst(iteratee, test, callback) {
- callback = callback || noop;
+ callback = onlyOnce(callback || noop);
var next = rest(function(err, args) {
if (err) return callback(err);
if (test.apply(this, args)) return iteratee(next);
diff --git a/lib/during.js b/lib/during.js
index e25d90a..549ad44 100644
--- a/lib/during.js
+++ b/lib/during.js
@@ -1,4 +1,5 @@
import noop from 'lodash/noop';
+import onlyOnce from './internal/onlyOnce';
/**
* Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
@@ -38,7 +39,7 @@ import noop from 'lodash/noop';
* );
*/
export default function during(test, fn, callback) {
- callback = callback || noop;
+ callback = onlyOnce(callback || noop);
function next(err) {
if (err) return callback(err);
diff --git a/lib/whilst.js b/lib/whilst.js
index e11a141..9012144 100644
--- a/lib/whilst.js
+++ b/lib/whilst.js
@@ -1,6 +1,8 @@
import noop from 'lodash/noop';
import rest from 'lodash/rest';
+import onlyOnce from './internal/onlyOnce';
+
/**
* Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when
* stopped, or an error occurs.
@@ -37,7 +39,7 @@ import rest from 'lodash/rest';
* );
*/
export default function whilst(test, iteratee, callback) {
- callback = callback || noop;
+ callback = onlyOnce(callback || noop);
if (!test()) return callback(null);
var next = rest(function(err, args) {
if (err) return callback(err);