Edit: 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.
You can even link cancellation tokens together and have different cancellation "roots".
It's hard to miss all the warnings unless you're literally just looking at the method name and nothing else.
The control flow stops because statements after `await new Promise(() => {});` will never run.
GC is only relied upon to not create a memory leak, but you could argue it's the same for all other objects.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The library will get additional maintainers until it balloons into 100Kloc with features like reading config files, which would need to eventually get split into a transitive dependency called configy, until one day a maintainer clicks on an enlarge penis link or gets phished by a fake AI girlfriend that was actually a russian dude, and it hits half of the javascript ecosystem because it had become a transitive dependency for every single package, and then everyone switches to a new package manager that somehow survived this due to a security feature, (but it was actually because no one uses that package manager and so the attacker didn't target it) also it's faster and used by the top startups of YC so it's very sexy and it can now be your girlfriend so you don't need a fake AI girlfriend and devs don't get supply chained anymore.
You think you do, but...
dimitropoulos•2h ago
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. yet. generators still haven't crossed over the magic barrier for some reason.
yeittrue•1h ago
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.
horsawlarway•1h ago
I don't really see generators ever crossing into mainstream usage in the same way as the other features you've compared them to. Most times... you just don't need them. The other language tools solve the problem in a more widely accessible manner.
In the (very limited & niche) subset of spots you do actually need a generator, they're nice to have, but it's mostly a "library author" tool, and even in that scope it's usage just isn't warranted all that often.
gbuk2013•29m ago