summaryrefslogtreecommitdiff
path: root/docs/v3/detect.js.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/v3/detect.js.html')
-rw-r--r--docs/v3/detect.js.html45
1 files changed, 40 insertions, 5 deletions
diff --git a/docs/v3/detect.js.html b/docs/v3/detect.js.html
index fe6d4c9..056000e 100644
--- a/docs/v3/detect.js.html
+++ b/docs/v3/detect.js.html
@@ -107,13 +107,48 @@ import awaitify from './internal/awaitify'
* @returns A Promise, if no callback is passed
* @example
*
- * async.detect(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, result) {
+ * // dir1 is a directory that contains file1.txt, file2.txt
+ * // dir2 is a directory that contains file3.txt, file4.txt
+ * // dir3 is a directory that contains file5.txt
+ *
+ * // asynchronous function that checks if a file exists
+ * function fileExists(file, callback) {
+ * fs.access(file, fs.constants.F_OK, (err) => {
+ * callback(null, !err);
+ * });
+ * }
+ *
+ * async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists,
+ * function(err, result) {
+ * console.log(result);
+ * // dir1/file1.txt
+ * // result now equals the first file in the list that exists
+ * }
+ *);
+ *
+ * // Using Promises
+ * async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists)
+ * .then(result => {
+ * console.log(result);
+ * // dir1/file1.txt
* // result now equals the first file in the list that exists
+ * }).catch(err => {
+ * console.log(err);
* });
+ *
+ * // Using async/await
+ * async () => {
+ * try {
+ * let result = await async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists);
+ * console.log(result);
+ * // dir1/file1.txt
+ * // result now equals the file in the list that exists
+ * }
+ * catch (err) {
+ * console.log(err);
+ * }
+ * }
+ *
*/
function detect(coll, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOf, coll, iteratee, callback)