Start a new topic

async waterfall

Any chance you will support 'waterfall' in the async module?

Ah, I haven't been able to try anything yet since I'm still waiting on a fix for the Ubuntu CLI. At this point, I would just start searching github for promise libraries and making sure they don't have setTimeout anywhere :-/
I tried it today with Q but setTimeout isn't supported so the whole thing just ends up failing.



Not really sure where to go with this when any setTimeout usage kills it.
I'm still waiting for a working Ubuntu version of the CLI, but I'll let you know if and when I am able to try something!
have you had any luck loading a library into utils?



I can't even get the example they have to work.
No problem, glad to be of help! :-)
oh wow I totally missed the "common code" section of that doc.



I actually kept getting frustrated not being able to use promises... yeah, guess I should add one there.



Thanks!
sorry about the formatting, here's a gist: https://gist.github.com/micmarsh/f9cecb02af47d3bdfe3c
I've actually implemented a quick and dirty version of waterfall in one of our collection hooks:



```function waterfall (functions, callback) {

var execute = function (functions, lastResult) {

if(!functions.length){

callback(null, lastResult);

}else{

functions[0](lastResult, function(error, newResult) {

execute(functions.slice(1), newResult);

});

}

};

//first function takes only a callback

functions[0]( function (error, result){

execute(functions.slice(1), result);

});

}```



However, promises (used in the javascript sdk) are generally awesome, and coincidentally all but eliminate the need for "waterfall" once you convert callback-based code to being promise-based. If you have access to a working version of the BL CLI (http://devcenter.kinvey.com/nodejs/tutorials/business-logic-revisions), I'd **highly** recommend investing time in add a good promises library to "common code", and converting as much of your BL to be promise-based as humanly possible (we plan to do this as soon as a CLI issue on Ubuntu is ironed out)
Login or Signup to post a comment