Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
foreachasync
Advanced tools
Readme
| A Root project
Analogous to [].forEach
, but handles items asynchronously with a final callback passed to then
.
This is the most essential piece of the ArrayAsync
package.
For cases where you want to loop through batches of items at once (as opposed to strictly one-by-one as forEachAsync does), check out forAllAsync
and lateral
.
For cases where you want to loop through all items at once and we able to know when they're all done see join
We jumped from 3.x to 5.x because I'm considering creating a backwards-and-forwards compatible 4.x that uses AngularJS-style function introspection to allow for having the next param. Straight up, that's probably a bad idea and waste of time so I hope I don't actually do it.
// EXAMPLE ASYNC FUNCTION
function getPicsAsync(animal) {
var flickerApi = "http://api.flickr.com/services/feeds/photos_public.gne?tagmode=any&format=json&tags=" + animal;
return requestAsync({ url: flickerApi });
}
forEachAsync(['dogs', 'cats', 'octocats'], function (element) {
return getPicsAsync(element);
}).then(function () {
// then after all of the elements have been handled
// the final callback fires to let you know it's all done
console.log('All requests have finished');
});
If native ES6 promises are not available, then you should supply your own Promises/A+ implementation like so:
forEachAsync = forEachAsync.create(window.Promise || require('bluebird'));
You can install from bower:
bower install --save forEachAsync@5.x
Or download the raw file from https://git.coolaj86.com/coolaj86/foreachasync.js/raw/branch/master/foreachasync.js:
wget https://git.coolaj86.com/coolaj86/foreachasync.js/raw/branch/master/foreachasync.js
(function () {
'use strict';
var forEachAsync = window.forEachAsync;
// do stuff ...
}());
Note: If you need both 3.x/4.x and 5.x version of forEachAsync
in the browser... good luck with that...
npm install --save foreachasync@5.x
forEachAsync(array, callback[, thisArg])
Parameters
array
Array of elements to iterate overcallback
Function to execute for each element, takes 4 arguments
element
a single element of the aforementioned arrayindex
the index of the current elementarray
the same array mentioned abovethisArg
Object to use as this
when executing callback
forEachAsync#then(done)
Parameters
then
is in the return value of forEachAsync
and accepts a final done
callback.
done
called after forEachAsync
is complete, takes no argumentsforEachAsync.__BREAK
This is used internally for the purposes of the ArrayAsync
library.
Please don't break
stuff; use ArrayAsync
.someAsync
or ArrayAsync
.everyAsync
instead.
FAQs
A node- and browser-ready async (now with promises) counterpart of Array.prototype.forEach
The npm package foreachasync receives a total of 502,602 weekly downloads. As such, foreachasync popularity was classified as popular.
We found that foreachasync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.