Saturday 22 July 2017

Question about promise and callback

Hi, I've recently discover all the power of the promises. But like many newbie I fall in the trap of using this paradigme most of the time (even when I don't need it). So basically most of my route are like that : /my-routeparams = {all object from the req I formatted in the first function}myFunction1(params)then(myFunction2)then(myFunction3)then(myFunction4)then(myFunction5)then(function(params){send result})catch(send error) Note: Param is an object where every function modify/add property to it. Until the final result. In one side, it's really really clear. I can move/remove/comment functions in 1 second. And catch the error quite easily. But I don't at what extend it's slower. But it is definitively slower than callback. I have to add to that (yes, i'm really trapped!) that most the function in the process called themselves other promises. It's a bit complicated, but put simply I have to generate data and file and then return a urls of those file. So there are Q.all() here and there. So my questions : 1) Is there a design pattern to have the power of promise but without falling in this trap 2) Is it a good practice to use promise on long process (but non async) ? I know there are some function that can take 50-100ms because of cpu calculation. 3) Any advice for me Thank you so much for your feedback. (my code really need it!)

Submitted July 22, 2017 at 01:13PM by pauldupont34

No comments:

Post a Comment