summaryrefslogtreecommitdiff
path: root/lib/detect.js
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2018-09-30 17:00:10 -0700
committerGitHub <noreply@github.com>2018-09-30 17:00:10 -0700
commit8aecf108b3922bc5211036706a0f6f75e02bd42b (patch)
tree0f7b6bee315231ef4aefdfbee154822921de231f /lib/detect.js
parentdf41256f49c9bb3126e035c95aca7860329b6acf (diff)
downloadasync-8aecf108b3922bc5211036706a0f6f75e02bd42b.tar.gz
feat: await-able Async methods (#1572)
* make each and family awaitable * dont pretend they're AsyncFunctions * check errors * ensure function name is preserved somehow * awaitable concat * awaitable detect * awaitable every/filter * awaitable groupBy * awaitable map/mapValues * awaitable reduce * awaitable reject * awaitable some * awaitable transform * awaitable times * awaitable auto * awaitable compose/seq * awaitable whilst/until (lol) * awaitable forever * awaitable parallel/race * awaitable retry * awaitable series (lol) * awaitable tryEach * awaitable waterfall (lol) * lint * cleanup, remove noop and unused internal functions
Diffstat (limited to 'lib/detect.js')
-rw-r--r--lib/detect.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/detect.js b/lib/detect.js
index 3e28f0e..4a6746a 100644
--- a/lib/detect.js
+++ b/lib/detect.js
@@ -1,5 +1,6 @@
import createTester from './internal/createTester';
-import doParallel from './internal/doParallel';
+import eachOf from './eachOf'
+import awaitify from './internal/awaitify'
/**
* Returns the first value in `coll` that passes an async truth test. The
@@ -26,6 +27,7 @@ import doParallel from './internal/doParallel';
* Result will be the first item in the array that passes the truth test
* (iteratee) or the value `undefined` if none passed. Invoked with
* (err, result).
+ * @returns A Promise, if no callback is passed
* @example
*
* async.detect(['file1','file2','file3'], function(filePath, callback) {
@@ -36,4 +38,7 @@ import doParallel from './internal/doParallel';
* // result now equals the first file in the list that exists
* });
*/
-export default doParallel(createTester(bool => bool, (res, item) => item));
+function detect(coll, iteratee, callback) {
+ return createTester(bool => bool, (res, item) => item)(eachOf, coll, iteratee, callback)
+}
+export default awaitify(detect, 3)