Can anyone come up with a reasonable explanation of how async/await, (synchronous) generators, and coroutines relate to each other on a conceptual level? Not specific to any one language

@joepie91 async functions return a thunk (think an uncomputed value), await waits until that thunk is resolved.

Generators are just "freeze points" in functions so that you can make iterators as well as fake concurrency.

@cadey It feels like both are variants on the same mechanism, though, and various sources are implying as such, but nobody seems to actually be finishing the thought

@joepie91 They basically are yeah, but usually async functions only have one possible return point but generators can have infinite possible return points.

@cadey In the sense that async functions always return / yield control to "the event loop implementation", but generators return / yield control to whatever the call-site was?

@cadey Thanks, that confirms my general sense of it then, I think :)

· · Web · 0 · 0 · 0
Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.