I'm looking to have better flow control for this async waterfall function.
async.waterfall([
async.apply(osxAppIconName, options.appFile),
function(iconFileName, callback) {
var existingIcon = path.join(options.iconDirectory, iconFileName);
return callback(null, existingIcon);
},
async.apply(fs.copy, options.iconFile), //automatically puts in existingIcon
async.apply(osxAppIconTouch, options.appFile),
], callback);
Right now I'm using async.apply which will inject global function arguments. In this case above I'm good, it takes existingIcon and will add it as the second-to-last argument in fs.copy. Making fs.copy's arguments options.iconfile, exitingIcon, callback [function]. Which is great!
However, let's say I need exitingIcon later on. Let's say I push this into my waterfall functions array.
async.apply(newFunction, existingIcon)
How would I get existingIcon to this function? Globals? It seems like a headache to manage! I also think that the async.apply function is executing on load, so if I pass it a variable it's gonna use the value of the variable when async.apply executes.
Thoughts? I have a proposal for async.switchboard here. Which attempts to solve this, but it doesn't work.
There's a nifty way around this using
async.autowhich attaches the result of a function to a prop in the chain.For promises check out: