-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's with the arrow effects on Promises? #13
Comments
The handling o the promises being resolved appear to be nested properly to show dependency on the parent from my perspective - if there is a less performant we'd welcome a pull request that demonstrates an issue / solution. A useless return statement isn't less performant as far as I know where as a conditional check with a return to prevent executing a code block would indeed be less performant, so in this regard as long as we have some tests or reasons to improve the code-base it would definitely be accepted. |
The most important aspect of this in my opinion is that this is not idiomatic JS and it makes for really hard to read/understand code. As a poster child example, of course the useless The perf aspect is related to memory pressure. Consider a chain of Promises A -> B -> C -> D. Implementation (1) is to do Observe that in case (1) it is only when the chain is complete (D resolves) that Case (2) is better because as soon as To put it otherwise, in case (1) client code waits on It is also different from a polyfill point of view. A polyfill typically uses |
@jods4 We would definitely be interested in a PR to improve this. I wrote that code in haste a month or so ago and hadn't had time to think about it much since. We would appreciate your assistance in improving these issues. Do you have a resource I can read related to the information you have above? In some of my reading I thought I read that nesting the promises was preferred in order to not lose errors that might occur...but maybe I remembered that wrong or maybe the source I had was wrong. In any case, we are open to making improvements, especially those that improve performance and lower memory pressure. Please sign our CLA (if you haven't already) and submit a PR. We'd be happy to accept it. |
@EisenbergEffect I have signed the CLA already. If you take PR for this I might have a look at it when I have some time, but that may not be soon as I have a lot of work right now. <_< Errors flow through the Promise chain. So if you do Note that you can continue the chain from there. Once the rejection has been handled everything resolves again, e.g.: if you do |
@jods4 Thanks for taking time to write up some information. I know you're busy and thank you for being willing to engage and help us make Aurelia better. |
Hey guys, this is "Rookie Mistake #1" in Nolan Lawson's (of PouchDB) article here: http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html I noticed the pyramid right away, too. There is not a performance problem here, but rather a subtle but significant lack of understanding in how promises work. I was in the same boat, so I know first-hand that correcting this will help you use and debug promises more effectively. |
Yes, you are 100% correct. This needs to be fixed. @sethlivingston Would you be willing to create a PR to fix it? 😄 |
I have it ready and will submit when #99 gets done. (And please point me somewhere if that's one I can help with, too. I'm assuming it's a general update needed for multiple Aurelia repos, but maybe I'm wrong.) |
#99 is all resolved now, thanks again for contributing @sethlivingston |
Closed by community PR. |
I was reading some Aurelia source code and I really couldn't help but notice those terrible pyramids of
Promise
. Look for instance atdialog-controller.js
for a short file where the style of coding is obvious.One (smaller) benefit of the
Promise
API is that we can flatten our code compared to callbacks and put all the.then()
on the same level:I understand that returning the first
.then()
rather than the nested ones has a subtly different semantic and behavior, but I can't find a reason for that in the code.Actually, it seems to me that it makes more sense to return the last promise in the chain and not the first one.EDIT: actually I think that given how the returns are nested the end result is exactly the same, but the code is less readable and less performant.Other example:
https://github.com/aurelia/dialog/blob/master/src/dialog-service.js#L44
Also note that the
return
on this line (L44) is useless.The text was updated successfully, but these errors were encountered: