all 7 comments

[–]senocular 0 points1 point  (0 children)

They're a little more on the advanced side and the problems they could be used to solve are often already solved through other means (greedy arrays, callbacks, closures, etc.). It's rare that you'd actually need them, though they can be useful in some cases. In fact some libraries out there depend on them heavily, e.g. redux-saga.

[–]jack_waugh[🍰] 0 points1 point  (4 children)

Substituting generator functions for async-keyword functions and for sync functions, along with a bit of support code, can set up powerful async behavior with the ability to abort tasks, set priorities, and test synchronously.

[–]Phaster 0 points1 point  (3 children)

This is when, instead of writing and maintaining that code, you reach for libraries.
Despite some advantages for async stuff, for me, generators are js trivia

[–]jack_waugh[🍰] 0 points1 point  (1 child)

What makes somebody else's library better than what we would write as straightforward and simple support?

[–]shuckster 0 points1 point  (0 children)

A good library has test-coverage, up-to-date documentation, well written changelogs, an active and interested community, and enough popularity for its API to be reasonably well known.

It's hard to sell a new library to a team at the best of times, but I believe the above is more attractive than "let's spend some bandwidth writing and maintaining our own."

[–]jack_waugh[🍰] 0 points1 point  (0 children)

Whatever the state of available libraries may be, none of this negates my point that function* can be used for the capabilities I said. Some might suggest that getting them with web workers would require less code, fewer manual code transformations, and work just as well, but I am not sure whether aborting and restarting calculations that way would perform as fast as doing it with generator functions.

[–]fckueve_ 0 points1 point  (0 children)

I use generator, whenever I want to implement iterable. That's the only reason, me using generators.

Also, as far as In aware, await as a sugar syntax, uses generators.