
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
N(ode) E(each)
If you are doing 'heavy lifting' loops in Node.js you can fork and allocate a new thread. But what if you want to run the loop in the same process and distribute iterations through multiple Event Loop cycles?
Node Each is here to solve the later. It avoids blocking Node.js Event Loop while performing asynchronous and intensive for each loops. It allows to set next iteration to be run on the next Event Loop cycle, giving the opportunity for Node to process queued events.
$ npm install node-each
var ne = require('node-each');
Array: [*]
Array to run each loop.
Callback: Function(el, i)
If the callback function returns a Promise back to the iterator handler, the next iteration will only run after Promise fulfilment.
Options: Object{debug, on, when}
Trigger next Event Loop cycle iteration based 'on' iteration number or time in milliseconds since the last cycle.
By default it will trigger based 'on' iteration every time it reaches 'when', in this case 1. Simply put on every loop iteration.
NE uses process.hrtime() to calculate time, so decimals can be used to work with smaller units.
Returns: Promise{fulfilled(debug)}
Debug: Object{average, cycles, duration, iterations, on, when}
Object{executing}: Number
var ne = require('node-each');
var names = ['Helen', 'John', 'Peter', 'Jim'];
var options = {
debug: true
};
ne.each(names, function(el, i){
console.log('Name', el + ' has index of ' + i);
}, options).then(function(debug) {
console.log('Finished', debug);
});
// Output
// Name Helen has index of 0 - Event Loop Cycle 1
// Name John has index of 1 - Event Loop Cycle 2
// Name Peter has index of 2 - Event Loop Cycle 3
// Name Jim has index of 3 - Event Loop Cycle 4
// Finished {
// average: 1.58539575,
// cycles: 4,
// duration: 6.341583,
// iterations: 4,
// on: 'iteration',
// when: 1
// }
var options = {
debug: true,
on: 'time',
when: 150.000001 // equals to 150000001 nanoseconds
};
/** Simulate asynchronous loop operation */
ne.each(names, function(el, i){
return new Promise(function(resolve) {
setTimeout(function(){
console.log('Name', el + ' has index of ' + i);
console.log('Loops executing', ne.stats.executing);
resolve();
}, 100);
});
}, options).then(function(debug) {
console.log('Finished', debug);
console.log('Loops executing', ne.stats.executing);
});
// Output
// Name Helen has index of 0 - Event Loop Cycle 1
// Loops executing 1
// Name John has index of 1 - Event Loop Cycle 1
// Loops executing 1
// Name Peter has index of 2 - Event Loop Cycle 2
// Loops executing 1
// Name Jim has index of 3 - Event Loop Cycle 2
// Loops executing 1
// Finished {
// average: 105.3162665,
// cycles: 2,
// duration: 421.265066,
// iterations: 4,
// on: 'time',
// when: 150
// }
// Loops executing 0
Node Each module uses semantic-release with Commit Guidelines.
$ mkdir node-each && cd node-each
$ git clone git@github.com:goncaloneves/node-each.git .
$ npm install
$ npm test # Tests with Coverage
$ npm run commit # Commit
$ gulp # Gulp Watch [Eslint, Test]
$ gulp lint # Gulp Eslint
$ gulp test # Gulp Tests
MIT License 2015 © Gonçalo Neves
FAQs
Node asynchronous for each that avoids blocking Node Event Loop
We found that node-each 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.