javascript - Rejecting and then Resolving a Q Promise -
I have seen a code that looks like this:
var defer = Q. Defer (); // Do something, if there is a callback here (mistake) {defer.reject ({err: err})} defer.resolve ({success: data}); // stop callback return defer.promise; If a promise has previously been rejected, and then resolved, then it seems that "rejection" remains.
When I first saw this pattern, I'd suggest wrapping the resolution inside a else , but since it works, is it an acceptable pattern? ?
Can there ever be a problem to reject and then resolve a promise?
It seems that if you solve and then reject, then the resolution remains. So whatever happens before, what is "rods"?
So whichever is first, what is "blackjack"?
Yes, of course. It has been promised that once the promise of the situation is volatile (full or rejected). No, there can not be any problem here, if the rejection is the first, then the promise is "dismissed".
However, think about whether someone else actually does not improve the quality of your code. Less code lines do not necessarily improve code readability! I would say, because it will be easy to understand what happens if you / if what if someone else should see your code, and they do not even know that the promises are settled after the settlement?
There is a great resource to understand more about the promise and that is what conforms to Q. The latter is more of the "source of truth", but it is hard to read (well, this is a fantasy).
Comments
Post a Comment