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
Removed promise antipattern from code example #227
Conversation
See [What is the explicit promise construction antipattern and how do I avoid it?](https://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it) on StackOverflow
This looks correct to me. Dunno if there's a style that should be followed regarding semicolons, but the use of promises seems correct. |
@bergus, could you add yourself to the acknowledgments section? |
This was discussed a bit during the merge. There is a slight problem here, which is that the form @bergus advocates will cause memory to be consumed for the entire chain of promises (i.e. the first chunk's promise cannot be GCed until the last chunk's promise is GCed, which does not happen until the stream is closed/errored). This is a design flaw/bug of promises, discussed a lot previously in tc39/proposal-cancelable-promises#1 and linked places. I am on the fence on this, but maybe it is better to advocate the "leaky" pattern in the hopes that we will one day fix it/optimize it in implementations? |
What leaks here? Just the promise object, or the chunks too? |
Just promise objects. The individual promises fulfilled with each chunk are not retained. Instead it's just a long chain of pending promises resolved to the next item in the chain, until the last promise is finally fulfilled. |
I think that's probably ok in this case. Hopefully implementations can squash that chain? |
Ah yeah the recursive promise chain memory problem. |
Yeah, it's unfortunate that it's not a trivial fix (since the easy fix breaks the ability for subclasses to customize |
@bergus no, it's completely up to you and only if you want to be listed. No requirements. |
@bergus ping. |
PR: #227 (Anne also snuck in a comment that he forgot to add in the previous commit.)
Thank you, landed as af4664d. Assumed you did not want to be listed at all. |
Thanks, it's fine. If I'll change my mind and want to be acknowledged, I'll find something else to contribute :-) |
See What is the explicit promise construction antipattern and how do I avoid it? on StackOverflow.
Promise evangelists say it should be burned with fire, and not appear in any possibly educational code examples :-)