MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/75nibr/javascripts_promise_is_memory_unsafe/do7t0ld/?context=3
r/javascript • u/alexelcu • Oct 11 '17
77 comments sorted by
View all comments
5
Seems interesting, if you find yourself needing to use infinitely recursive promises.
Say you remove promises from this problem though:
function loop(n) {
const i = signal(n);
if (i % 1000 == 0) console.log(i);
return loop(n + 1);
}
Would you say JavaScript is doing something wrong if it "leaks" when you run that code?
What's the difference here?
5 u/alexelcu Oct 11 '17 The result is that the stack blows up, triggering a stack overflow error.Yes, it's a mistake, explaining the reason for why is a little difficult, I tried doing that in a comment here.But also consider that if this wouldn't be a mistake, then they wouldn't be implementing TCO in ECMAScript 6: http://2ality.com/2015/06/tail-call-optimization.html
The result is that the stack blows up, triggering a stack overflow error.
Yes, it's a mistake, explaining the reason for why is a little difficult, I tried doing that in a comment here.
But also consider that if this wouldn't be a mistake, then they wouldn't be implementing TCO in ECMAScript 6: http://2ality.com/2015/06/tail-call-optimization.html
5
u/PM_YOUR_WORST_FEAR Oct 11 '17
Seems interesting, if you find yourself needing to use infinitely recursive promises.
Say you remove promises from this problem though:
Would you say JavaScript is doing something wrong if it "leaks" when you run that code?
What's the difference here?