summaryrefslogtreecommitdiff
path: root/lib/reject.js
diff options
context:
space:
mode:
authorRoman Lorenzo Balayan <roman.balayan@gmail.com>2021-08-06 06:58:10 +0800
committerGitHub <noreply@github.com>2021-08-05 15:58:10 -0700
commit159a119fbb1a585c61f33b4b3b5036f5d332ebbb (patch)
treebbf78b2e8899c412ceede4a705d45368f61b51bf /lib/reject.js
parent89255fe326050e80ce5394a9c00e11e9be8b1005 (diff)
downloadasync-159a119fbb1a585c61f33b4b3b5036f5d332ebbb.tar.gz
Enhance examples for Collections methods. (#1726)
* Enhance examples for Collections methods. * Update collection example code, avoiding usage of IIFE on async/await examples * Convert examples on async.auto, async.series, and async.parallel to samples using Promises and async/await Co-authored-by: Roman Balayan <roman.balayan@paymaya.com>
Diffstat (limited to 'lib/reject.js')
-rw-r--r--lib/reject.js48
1 files changed, 41 insertions, 7 deletions
diff --git a/lib/reject.js b/lib/reject.js
index c1de825..127430e 100644
--- a/lib/reject.js
+++ b/lib/reject.js
@@ -21,14 +21,48 @@ import awaitify from './internal/awaitify'
* @returns {Promise} a promise, if no callback is passed
* @example
*
- * async.reject(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, results) {
- * // results now equals an array of missing files
- * createFiles(results);
+ * // 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
+ *
+ * const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
+ *
+ * // asynchronous function that checks if a file exists
+ * function fileExists(file, callback) {
+ * fs.access(file, fs.constants.F_OK, (err) => {
+ * callback(null, !err);
+ * });
+ * }
+ *
+ * // Using callbacks
+ * async.reject(fileList, fileExists, function(err, results) {
+ * // [ 'dir3/file6.txt' ]
+ * // results now equals an array of the non-existing files
* });
+ *
+ * // Using Promises
+ * async.reject(fileList, fileExists)
+ * .then( results => {
+ * console.log(results);
+ * // [ 'dir3/file6.txt' ]
+ * // results now equals an array of the non-existing files
+ * }).catch( err => {
+ * console.log(err);
+ * });
+ *
+ * // Using async/await
+ * async () => {
+ * try {
+ * let results = await async.reject(fileList, fileExists);
+ * console.log(results);
+ * // [ 'dir3/file6.txt' ]
+ * // results now equals an array of the non-existing files
+ * }
+ * catch (err) {
+ * console.log(err);
+ * }
+ * }
+ *
*/
function reject (coll, iteratee, callback) {
return _reject(eachOf, coll, iteratee, callback)