I'm using bluebird to design some nodejs api wrapper around an http service.
Many of the functions in this wrapper are asynchronous and so it makes a lot of sense to return promises from these implementation.
My colleague has been working on the project for a few days now and interesting pattern is emerging, he is also returning promises from synchronously implemented functions.
Example:
function parseArray(someArray){
var result;
// synchronous implementation
return Promise.resolve(result);
}
I can see how this could be useful if later on the implementation needs to be made asynchronous, as you wouldn't have to refactor the call sites.
I guess it's also nice that all methods are consistently "async", but I'm not sure how awesome that exactly is.
Is this considered a bad practice, are there any reasons why we shouldn't do this ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…