summaryrefslogtreecommitdiff
path: root/lib/tryEach.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tryEach.js')
-rw-r--r--lib/tryEach.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/tryEach.js b/lib/tryEach.js
index af885dc..6677c9d 100644
--- a/lib/tryEach.js
+++ b/lib/tryEach.js
@@ -1,6 +1,6 @@
import eachSeries from './eachSeries';
-import noop from './internal/noop';
import wrapAsync from './internal/wrapAsync';
+import awaitify from './internal/awaitify'
/**
* It runs each task in series but stops whenever any of the functions were
@@ -21,6 +21,7 @@ import wrapAsync from './internal/wrapAsync';
* of the tasks has succeeded, or all have failed. It receives the `err` and
* `result` arguments of the last attempt at completing the `task`. Invoked with
* (err, results).
+ * @returns {Promise} a promise, if no callback is passed
* @example
* async.tryEach([
* function getDataFromFirstWebsite(callback) {
@@ -39,11 +40,10 @@ import wrapAsync from './internal/wrapAsync';
* });
*
*/
-export default function tryEach(tasks, callback) {
+function tryEach(tasks, callback) {
var error = null;
var result;
- callback = callback || noop;
- eachSeries(tasks, (task, taskCb) => {
+ return eachSeries(tasks, (task, taskCb) => {
wrapAsync(task)((err, ...args) => {
if (args.length < 2) {
[result] = args;
@@ -55,3 +55,5 @@ export default function tryEach(tasks, callback) {
});
}, () => callback(error, result));
}
+
+export default awaitify(tryEach)