Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Autoflow (formerly named react) is a javascript module implementing a control-flow / flow control engine to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and
autoflow (formerly named react) is a javascript module to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and task dependencies when defining flow. This project is applying the concepts of Reactive programming or Dataflow to controlling application flow.
This async flow control module is initially designed to work with Node.js but is planned to be extended to browser and other environments.
Autoflow (formerly named react) got its original name from similarities with how "chain reactions" work in the physical world. You start the reaction and then it cascades and continues until complete.
Also "Reactive Programming" or "Dataflow" describe defining flow which reacts to the data similar to how a spreadsheet updates cells. These are good examples of how autoflow controls flow based on when data is available
It takes inspiration from several projects including:
autoflow.resolvePromises();
)The tasks can be mixed, meaning you can use async, sync, object method calls, class method calls, etc in the same flow.
Borrowing heavily from Tim and Elijah's ideas for conductor, this async flow control module provides a way to construct a flow from a collection of rules based on functions or methods (referred to as tasks in this module). It allows dependencies to be defined between the tasks so they can run in parallel as their dependencies are satisfied. autoflow can use both variable dependencies and task dependencies.
As tasks complete, autoflow watches the dependencies and kicks off additional tasks that have all their dependencies met and are ready to execute. This allows the flow to run at maximum speed without needing to arbitrarily block tasks into groups of parallel and serial flow.
To reduce the boilerplate code needed and improve error handling, autoflow automatically provides callback functions for your asynchronous code. These autoflow-provided callback functions perform these steps:
npm install autoflow
OR
Pull from github - http://github.com/jeffbski/autoflow
Simple example showing flow definition of two async functions feeding a synchronous function.
First two async functions inputs are satisfied by the flow inputs, so they will both run immediately in parallel.
The last function waits for the outputs of the previous ones, then executes synchronously.
Finally the flow calls the callback with the output values once all the tasks have completed.
// in your foobar module
var autoflow = require('autoflow');
// some normal async and sync functions
function loadFoo(fooPath, cb) {
setTimeout(function () {
cb(null, [fooPath, 'data'].join(':'));
}, 10);
}
function loadBar(barPath, barP2, cb) {
setTimeout(function () {
cb(null, [barPath, barP2, 'data'].join(':'));
}, 10);
}
function render(foo, bar) {
return ['<html>', foo, '/', bar, '</html>'].join('');
}
// define fn, glue together with autoflow, it will parallelize
// starts with name and in/out params, then the tasks
var loadRender = autoflow('loadRender', 'fooPath, barPath, barP2, cb -> err, renderedOut',
loadFoo, 'fooPath, cb -> err, foo', // async cb function
loadBar, 'barPath, barP2, cb -> err, bar', // async cb function
render, 'foo, bar -> renderedOut' // sync function using outputs from first two
);
exports.loadRender = loadRender; // is a normal fn created by autoflow
// in a different module far far away, use this as any other node function
var foobar = require('foobar');
foobar.loadRender('foo.txt', 'bar.txt', 'BBB', function (err, renderedOut) {
// tasks in loadRender were parallelized based on their input dependencies
console.error('results:', renderedOut);
});
Below is a graph of how the dependencies are mapped by autoflow which Also indicates how the tasks will be executed. This was generated by the autoflow plugin autoflow-graphviz which you can use to also graph your flows.
The main function returned from require('autoflow') can be used to define the AST used for the processing of the rules or flow.
It takes the following arguments to define a flow function:
var fn = autoflow('loadRender', 'fooPath, barPath, barP2, cb -> err, renderedOut',
loadFoo, 'fooPath, cb -> err, foo',
loadBar, 'barPath, barP2, cb -> err, bar',
render, 'foo, bar -> renderedOut'
);
Note: graphic uses the old name react
, new name is autoflow
->
. Use the parameter name cb
or callback
to specify the Node style callback and err
to represent the error parameter as the first output parameter of the callback. Literal values can also be specified directly (true, false, numbers, this, null). Literal strings can simply be quoted using single or double quotes.locals
property can contain an object map of any local variables you want to reference in the flow (other than what is passed in as parameters). For example: { locals: { foo: foo, bar: bar }}
would make local vars available in the flow. Note that global variables are already available in the flow.'obj.method'
. These can be asynchronous Node-style callback cb(err, ...)
functions or synchronous functions which simply return values directly.cb
or callback
along with err
to specify asynchronous Node style cb(err, ...)
task, or omit both to specify a synchronous task. A synchronous task can only have a single return parameter._index
(zero based index of the task) added to create unique name. If you specify a name, you will also want to indicate a unique name for within the flow otherwise it will get a suffix as well. Example: { name: 'myTaskName' }
{ after: 'foo' }
or { after: ['foo', 'bar'] }
after
option. If you want to guarantee that something only runs after something else completes, then it will need to use an output from that task or specify the dependency with an after
.The flow function created by autoflow from the input definition is a normal Node-style function which can be used like any other. These flow functions can be defined in a module and exported, they can be passed into other functions, used as methods on objects (the this
context is passed in and is available).
autoflow has a built-in plugin which can be loaded that will enable logging of tasks and flow as it executes, which is very useful for debugging. For full details see Advanced autoflow - LogEvents along with the other plugins and an explanation of the AST autoflow uses.
var autoflow = require('autoflow');
autoflow.logEvents(); // turn on flow and task logging for all autoflow functions
autoflow has many additional plugins and features which enable logging, monitoring, promise resolution, etc.
See The Advanced autoflow for details on the AST autoflow uses for processing and other plugins that are available.
mocha
178 tests complete
Source code repository: http://github.com/jeffbski/autoflow
Ideas and pull requests are encouraged - http://github.com/jeffbski/autoflow/issues
You may contact me at @jeffbski or through github at http://github.com/jeffbski
FAQs
Autoflow (formerly named react) is a javascript module implementing a control-flow / flow control engine to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and
We found that autoflow 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.