mercredi 8 mars 2017

Using promises in synchronous code [on hold]

I am working on a two man project in JS, and while we have been at it for some time, I have mainly been working on the code while the other guy have focused on environment (servers, buildscripts, databases etc.), with some backend coding to boot.

Now i fetched his latest branch, and saw synchronized code in a Promise pattern. Example below:

let classObj = new AClass();

classObj.op1('someStringData',  {})
.then(classObj.op2.bind(classObj, 'someOtherStringData'))
.then(classObj.op3.bind(classObj, anObject)) 
...
.catch((err) => {
  console.log(err);
});

Not regarding the bindings and code in particular, most of the op# functions are not even asynchronous, (but are wrapped in a Promise) which made me question the implementation and just do ordinary function calls. He claims it makes it more readable and that he wanted to adapt a more pipe-like implementation, and it is not 'wrong' to do this.

And while I might be appalled by the implementation, I was wondering, what is the actual downside of this? It has been discussed here, but is it bad enough to rewrite the code and give him a lesson of sync vs async, or just let it go (as it actually does the intended job).

I'm sorry if it seems to be much of a discussion question, but the main reason the the question is: Is there a drawback of this that make this implementation right out bad?

Aucun commentaire:

Enregistrer un commentaire