CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
each.js129 linesDownload Raw Back to async
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6 7var _eachOf = require('./eachOf.js');8 9var _eachOf2 = _interopRequireDefault(_eachOf);10 11var _withoutIndex = require('./internal/withoutIndex.js');12 13var _withoutIndex2 = _interopRequireDefault(_withoutIndex);14 15var _wrapAsync = require('./internal/wrapAsync.js');16 17var _wrapAsync2 = _interopRequireDefault(_wrapAsync);18 19var _awaitify = require('./internal/awaitify.js');20 21var _awaitify2 = _interopRequireDefault(_awaitify);22 23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }24 25/**26 * Applies the function `iteratee` to each item in `coll`, in parallel.27 * The `iteratee` is called with an item from the list, and a callback for when28 * it has finished. If the `iteratee` passes an error to its `callback`, the29 * main `callback` (for the `each` function) is immediately called with the30 * error.31 *32 * Note, that since this function applies `iteratee` to each item in parallel,33 * there is no guarantee that the iteratee functions will complete in order.34 *35 * @name each36 * @static37 * @memberOf module:Collections38 * @method39 * @alias forEach40 * @category Collection41 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.42 * @param {AsyncFunction} iteratee - An async function to apply to43 * each item in `coll`. Invoked with (item, callback).44 * The array index is not passed to the iteratee.45 * If you need the index, use `eachOf`.46 * @param {Function} [callback] - A callback which is called when all47 * `iteratee` functions have finished, or an error occurs. Invoked with (err).48 * @returns {Promise} a promise, if a callback is omitted49 * @example50 *51 * // dir1 is a directory that contains file1.txt, file2.txt52 * // dir2 is a directory that contains file3.txt, file4.txt53 * // dir3 is a directory that contains file5.txt54 * // dir4 does not exist55 *56 * const fileList = [ 'dir1/file2.txt', 'dir2/file3.txt', 'dir/file5.txt'];57 * const withMissingFileList = ['dir1/file1.txt', 'dir4/file2.txt'];58 *59 * // asynchronous function that deletes a file60 * const deleteFile = function(file, callback) {61 *     fs.unlink(file, callback);62 * };63 *64 * // Using callbacks65 * async.each(fileList, deleteFile, function(err) {66 *     if( err ) {67 *         console.log(err);68 *     } else {69 *         console.log('All files have been deleted successfully');70 *     }71 * });72 *73 * // Error Handling74 * async.each(withMissingFileList, deleteFile, function(err){75 *     console.log(err);76 *     // [ Error: ENOENT: no such file or directory ]77 *     // since dir4/file2.txt does not exist78 *     // dir1/file1.txt could have been deleted79 * });80 *81 * // Using Promises82 * async.each(fileList, deleteFile)83 * .then( () => {84 *     console.log('All files have been deleted successfully');85 * }).catch( err => {86 *     console.log(err);87 * });88 *89 * // Error Handling90 * async.each(fileList, deleteFile)91 * .then( () => {92 *     console.log('All files have been deleted successfully');93 * }).catch( err => {94 *     console.log(err);95 *     // [ Error: ENOENT: no such file or directory ]96 *     // since dir4/file2.txt does not exist97 *     // dir1/file1.txt could have been deleted98 * });99 *100 * // Using async/await101 * async () => {102 *     try {103 *         await async.each(files, deleteFile);104 *     }105 *     catch (err) {106 *         console.log(err);107 *     }108 * }109 *110 * // Error Handling111 * async () => {112 *     try {113 *         await async.each(withMissingFileList, deleteFile);114 *     }115 *     catch (err) {116 *         console.log(err);117 *         // [ Error: ENOENT: no such file or directory ]118 *         // since dir4/file2.txt does not exist119 *         // dir1/file1.txt could have been deleted120 *     }121 * }122 *123 */124function eachLimit(coll, iteratee, callback) {125    return (0, _eachOf2.default)(coll, (0, _withoutIndex2.default)((0, _wrapAsync2.default)(iteratee)), callback);126}127 128exports.default = (0, _awaitify2.default)(eachLimit, 3);129module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace