summaryrefslogtreecommitdiff
path: root/lib/reject.js
diff options
context:
space:
mode:
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)