Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/everyLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ import awaitify from './internal/awaitify.js'
* `iteratee` functions have finished. Result will be either `true` or `false`
* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example
*
* // Check up to two files at a time. Stops early on the first `false`.
* // dir1 is a directory that contains file1.txt, file2.txt
* // dir2 is a directory that contains file3.txt, file4.txt
* const fileList = ['dir1/file1.txt','dir2/file3.txt','dir1/file2.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.everyLimit(fileList, 2, fileExists, (err, result) => {
* if (err) throw err;
* console.log(result);
* // true
* // result is true since every file exists
* });
*
* // Omit the callback and everyLimit returns a Promise.
* const allExist = await async.everyLimit(fileList, 2, async (file) => {
* return fs.promises.access(file).then(() => true, () => false);
* });
* console.log(allExist);
* // true
*/
function everyLimit(coll, limit, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOfLimit(limit), coll, iteratee, callback)
Expand Down