Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
async-rollback
Advanced tools
A plugin for caolan's async module that add support to rollback successful async operations on failure.
#async-rollback
A plugin for caolan's async module that adds
additional async methods with improved integrity. For example, async.parallel
normally executes the callback immediately if any task returns an error, but this
is not always desired. async-rollback
contains a parallelRollback
method which
can undo parallel tasks that succeeded if one of the tasks fails.
To install using npm:
npm install async-rollback
To use, simply require('async-rollback')
near the beginning of your node code.
It augments the normal async
module so must only be required one time.
Run an array of functions in parallel, without waiting until the previous function has completed. If any of the functions pass an error to its callback, the error is cached until all tasks complete. Once the tasks have completed, the results are passed to the final callback as an array. If any functions passed errors, the main callbacks error argument will be an array, corresponding to the input functions.
It is also possible to use an object instead of an array. Each property will be run as a function and the results will be passed to the final callback as an object instead of an array. If any tasks result in an error, the final callbacks error argument will also be an object.
Arguments
Example
async.parallelAll([
function(callback){
setTimeout(function(){
callback(null, 'one');
}, 200);
},
function(callback){
setTimeout(function(){
callback('error2');
}, 100);
}
],
// optional callback
function(errs, results){
// errs = [null, 'error2']
// results = ['one', null]
if (errs)
console.log('Errors occurred');
});
// an example using an object instead of an array
async.parallel({
one: function(callback){
setTimeout(function(){
callback(null, 1);
}, 200);
},
two: function(callback){
setTimeout(function(){
callback(2, null);
}, 100);
}
},
function(errs, results) {
// errs = {one: null, two: 2}
// results = {one: 1, two: null}
if (errs)
console.log('Errors occurred');
});
Similar to parallel
and parallelAll
, except each task may have an undo
property that is executed if that task succeeds while others fail. This function
works with the typical arrays and objects of tasks (and behaves the same as
parallelAll
in this case), but accepts a new array (or object) format of
do
/ undo
functions. If any task (or tasks) fail, the undo
function of any
non-failing task will automatically be called. The final callback is executed
with an array (or object) of results (and possibly errors) after all tasks
and potential undo
functions have been called.
Arguments
do
/ undo
tasks to run. Each do
function is passed
a callback(err, result) it must call on completion with an error (which can
be null) and an optional result value. The undo
function may be called if the task
succeeds while others fail. The undo
function is passed the value of the do
function,
along with a callback(err) it must call on completion.Example
async.parallelRollback([
{
do : function(callback) {
uploadImage('image1.png', callback);
},
undo : function(result, callback) {
deleteImage(result, callback);
}
},
{
do : function(callback) {
uploadImage('image2.png', callback);
},
undo : function(result, callback) {
deleteImage(result, callback);
}
}
],
// optional callback
function(errs, results){
// With a typical .parallel() call, if one of the uploads failed then the other image would be left
// uploaded. By using .parallelRollback(), either both images or no images will get uploaded.
// For example, if the uploading of image2 fails, then the undo method of the first task will be called.
if (errs)
console.log('Errors occurred');
});
// an example using an object instead of an array
async.parallel({
image1 : {
do : function(callback) {
uploadImage('image1.png', callback);
},
undo : function(result, callback) {
deleteImage(result, callback);
}
},
image2 : {
do : function(callback) {
uploadImage('image2.png', callback);
},
undo : function(result, callback) {
deleteImage(result, callback);
}
}
},
function(errs, results) {
if (errs)
console.log('Errors occurred');
});
FAQs
A plugin for caolan's async module that add support to rollback successful async operations on failure.
We found that async-rollback 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.