You can't cancel a JavaScript promise (except sometimes you can)
1–10 of 66 posts
Re: You can't cancel a JavaScript promise (except sometimes you can)
#2I'm getting so tired of hearing this. I loved the article and it's interesting stuff, but how many more decades until people accept generators as a primitive??
used to hear the same thing about trailing commas, destructuring, classes (instead of iife), and so many more. yet. generators still haven't crossed over the magic barrier for some reason.
Re: You can't cancel a JavaScript promise (except sometimes you can)
#3Re: You can't cancel a JavaScript promise (except sometimes you can)
#4> Libraries like Effect have increased the popularity of generators, but it's still an unusual syntax for the vast majority of JavaScript developers. I'm getting so tired of hearing this. I loved the article and it's interesting stuff, but how many more decades until people accept generators as a primitive?? used to hear the same thing about trailing commas, destructuring, classes (instead of iife), and so many more.…
You're right, mostly pointless syntax (along with Promise) now that we can await an async function anyway, especially now with for .. of to work with Array methods like .map
But there are still some use cases for it, like with Promise. Like for example, making custom iterators/procedures or a custom delay function (sync) where you want to block execution.
Re: You can't cancel a JavaScript promise (except sometimes you can)
#5Re: You can't cancel a JavaScript promise (except sometimes you can)
#6Edit: note that there is a "wrong" way to do this as well. The Java thread library provides a stop() function. But since that's exogenous, it doesn't necessarily get cleaned up properly. We had to have an effort to purge it from our codebase after discovering that stopping a thread while GRPC was in progress broke all future GRPC calls from all threads, presumably due to some shared data structure being left inconsistent. "Cooperative" (as opposed to preemptive) cancel is much cleaner.
Re: You can't cancel a JavaScript promise (except sometimes you can)
#7Re: You can't cancel a JavaScript promise (except sometimes you can)
#8> Libraries like Effect have increased the popularity of generators, but it's still an unusual syntax for the vast majority of JavaScript developers. I'm getting so tired of hearing this. I loved the article and it's interesting stuff, but how many more decades until people accept generators as a primitive?? used to hear the same thing about trailing commas, destructuring, classes (instead of iife), and so many more.…
Re: You can't cancel a JavaScript promise (except sometimes you can)
#9https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re: You can't cancel a JavaScript promise (except sometimes you can)
#10I like how C# handles this. You're not forced to support cancellation, but it's strongly encouraged. The APIs all take a CancellationToken, which is driven by a CancellationTokenSource from the ultimate caller. This can then either be manually checked, or when you call a library API it will notice and throw an OperationCancelledException. Edit: note that there is a "wrong" way to do this as well. The Java thread libr…
You can even link cancellation tokens together and have different cancellation "roots".