
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.
functionflowx
Advanced tools
Control how the javascript functions will be executed.
The FunctionFlowX® controls whether functions will be executed in serial or in parallel sequence. It gives the possibility for iterative repetition of serial or parallel function sequence. It defines time delays between every function execution step. Finally, it controls the whole process to start, stop or pause. There is some similarity with the async npm library but FunctionFlow is much more powerful because it uses JS Promises and async/await.
$ npm install --save functionflowx
/*** NodeJS script ***/
const { EventEmitter } = require('events');
const FunctionFlow = require('functionflowx');
// functions
const f1 = (x, lib) => {
x++;
console.log('f1::', x);
return x;
};
const f2 = (x, lib) => {
x++;
console.log('f2::', x);
return x;
};
const f3 = function (x, lib) {
x++;
console.log('f3::', x);
console.log('this::', this); // {}
console.log('lib::', lib); // {evenEmitter,ff}
return x;
};
// main
const main = async (input, eventEmitter) => {
const ff = new FunctionFlow({ debug: true, msDelay: 800 }, eventEmitter);
const x = input;
const lib = { eventEmitter, ff };
ff.xInject(x);
ff.libInject(lib);
await ff.serial([f1, f2, f3, f1]);
await ff.delay(3400);
return ff.x;
};
// execute main
const inp = 5;
const eventEmitter = new EventEmitter();
main(inp, eventEmitter)
.then(res => console.log('RES:: ', res))
.catch(err => console.error('ERR:: ', err));
Other examples are in /tests/ folder.
Inject x (transitional variable) in function first parameter - func(x, lib).
Inject libraries like Cheerio, Puppeteer, ...etc. in function second parameter - func(x, lib).
Add libraries to libraries already injected by libInject().
Remove all libraries.
List all libraries.
Execute funcs functions one by one.
input------>|--f0-->|msDelay|--f3-->|msDelay|--f2-->|msDelay|------>output
Execute funcs functions one by one and repeat it for every array element. The funcs chain is repeated the arr.length times. The "arr" element is stored in the "lib.serialEachElement" and can be used inside the function.
input------>|--f0-->|msDelay|--f3-->|msDelay|--f2-->|msDelay|------>output
| arr|
|<--------------repeat arr.length --------------|
Execute funcs functions one by one and repeat it n times. The funcs chain is repeated the n times. The iteration number is stored in the "lib.serialRepeatIteration" and can be used in the function.
input------>|--f0-->|msDelay|--f3-->|msDelay|--f2-->|msDelay|------>output
| n|
|<-------------------repeat n ------------------|
Execute just one function.
Take any defined function and execute simultaneously. All defined functions must return fulfilled promises. Input is same for all functions. Returned value is an array of resolved values.
--> |--------- f2(x) ---------->---|
-- input --> |--------- f4(x) ------->------|msDelay|---> [r2, r4, r8]
--> |--------- f8(x) ------------->|
Run functions in paralell. Fastest function must return fulfilled promise. Returned value is value from first resolved (fastest) function.
--> |--------- f2(x) --------|-->
-- input --> |--------- f4(x) ------->|msDelay|---> r4
--> |--------- f8(x) --------|----->
Repeat last executed FunctionFlow bundle method (serial, serialEach, ...) n times.
Stops the execution of all functions used in bundle methods (serial, one or parallel). Condition: status = 'start'.
ff.stop(); // inside function
eventEmitter.emit('ff-stop'); // out of function
Starts/restarts function flow execution if it's previously been stopped or paused. Condition: status = 'pause' | 'stop'.
ff.start(); // inside function
eventEmitter.emit('ff-start'); // out of function
Pauses function flow execution used in bundle methods (serial, one or parallel). Condition: status = 'start'.
ff.pause(); // inside function
eventEmitter.emit('ff-pause'); // out of function
Go to the function used in the serial(funcs) method. Parameter goTo is the index number of funcs array and the condition 0 <= goTo < funcs.length must be fulfilled. When the execution of that function is finished, continue with the next function in funcs array. It's usually used to go to another function which is in the serial() method.
f2.js
------------------
module.exports = (x, lib) => {
x++;
lib.echo.log('f2:: ', x);
if (x < 13 ) { lib.ff.go(1); } // go back to f1
return x;
};
Stop execution of all funcs functions in serial(funcs) method and continue with the next serial, one or parallel bundle method. It will work only inside a function used in the serial() method. A parameter is not needed for this method.
f2.js
------------------
module.exports = (x, lib) => {
x++;
lib.echo.log('f2::', x);
lib.ff.next();
return x;
};
Jump to iteration number defined in the repeat(n) method. When that iteration is executed continue with the next iteration in repeat(n) method. The current iteration will finish with all its functions. Parameter jumpTo is the iteration number and the condition 0 < jumpTo <= n must be fulfilled. It's usually used to skip some iterations under certain conditions. To get a current iteration number use ff.iteration.
f2.js
------------------
module.exports = (x, lib) => {
x++;
lib.echo.log('f2::', x);
if (lib.ff.iteration === 2) { lib.ff.jump(10); } // on 2nd iteration jump to last iteration
return x;
};
Breaks all iterations in repeat(n) method. Parameter is not required. The current iteration will finish with all its functions. It sets this.jumpTo = Infinity. It's used inside the function to stop all repeats (iterations).
ffunc.js
------------------
module.exports = (x, lib) => {
x++;
if (x.val > 2) { lib.ff.break(); } // stop iterations defined in main.js by ff.repeat(n);
return x;
};
Delay in miliseconds.
await ff.delay(3400); // delay of 3.4 seconds
Random delay from msMin to msMax.
await ff.delayRnd(3000, 8000); // delay between 3 and 8 seconds
The software licensed under AGPL-3.
FAQs
Control how the javascript functions will be executed.
We found that functionflowx 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.