
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
method-invoker
Advanced tools
Modifies method invocation behavior.
npm install method-invoker
The example bellow shows how to limit the concurrency of a function while applying a delay to its execution.
var Invoker = require('../');
var startTime = Date.now();
var funcA = function() {
console.log('funcA', Date.now() - startTime);
};
var invoker = new Invoker()
.concurrency(2)
.delay(1000);
var funcB = invoker.decorate(funcA);
funcB();
funcB();
funcB();
funcB();
funcB();
/*
the output would be something like this:
funcA 1005
funcA 1006
funcA 2006
funcA 2006
funcA 3007
*/
This can also be used with an asynchronous function, like the example bellow:
var Invoker = require('../');
var startTime = Date.now();
var funcA = function(n, callback) {
console.log('funcA', Date.now() - startTime);
setTimeout(function() {
if (typeof callback === 'function') callback(n * 2);
}, 2000);
};
var invoker = new Invoker()
.gap(1000)
.params(Invoker.CALLBACK);
var funcB = invoker.decorate(funcA);
var callback = function() {
console.log('callback', Date.now() - startTime);
};
funcB(1).then(callback);
funcB(2).then(callback);
funcB(3).then(callback);
funcB(4).then(callback);
funcB(5).then(callback);
/*
the output should be something like this:
funcA 5
callback 2006
funcA 3007
callback 5009
funcA 6010
callback 8011
funcA 9013
callback 11015
funcA 12016
callback 14018
*/
First, you need a new Invoker for each invocation control (the same one can be applied to multiple functions, and all of them will share behavior).
var invoker = new Invoker();
This creates and retuns a new Invoker.
Returns a function decorator for filling the specified parameters. You can pass Invoker.CALLBACK as a replacement for the callback, which also indicates the function is asynchronous.
Returns a function decorator for retricting concurrency. This only makes sense for asynchronous functions.
Returns a function decorator for delaying the execution of a function.
Returns a function decorator for imposing a delay between calls.
Returns a function decorator for imposing a gap between the end of a function execution and the next call. This only makes sense for asynchronous functions.
Returns a function decorator for executing a function every X call.
Returns a function decorator for executing a function after X calls.
Returns a function decorator for executing a function at most X times.
Returns a function decorator for executing a function respecting the rate limit.
Adds the specified function to the list of decorators to be applied.
Decorates the specified function with all the configured methods, creating a new function that returns a Promise.
Returns a function with all the configured methods, that can be called with the function to be decorated.
All the static methods have a prototype version, which calls Invoker#execution on the returned decorator.
FAQs
Modifies method invocation behavior
We found that method-invoker 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.