var async = require('async') // // Function performs a certain task on a multiple uplinks // and reverts changes if something fails // // uplinks - list of uplinks not counting local // localAction, localRollback - function(cb) // remoteAction, remoteRollback - function(uplink, cb) // module.exports = function(uplinks, localAction, localRollback, remoteAction, remoteRollback, callback) { var uplink_ids = uplinks.map(function(_, i) { return i }) localAction(function(err) { if (err) return callback(err) async.map(uplink_ids, function(i, cb) { remoteAction(uplinks[i], function(err) { cb(null, err) }) }, function(err, res) { var return_err = err // let err be first non-null element in the array for (var i=0; i