Comment

Comment by baxuz

What are some use cases of using generators to do coroutines?

I honestly can't think of an example that couldn't be handled in a stateful way, by using objects/class instances instead of closures.

Even iteration can be handled by implementing [Symbol.iterator] on the instance.

The one place I found a use for them is to syncify async functions in some rare cases where it's needed, as the API would only work with other non-sync functions.

parent baxuz 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton