3 ms·
I remember being able to do this using Twisted in Python 2.6 or so, using the same techniques. At the time, the way to manipulate “deferred” results was to use
by orf 2y ago
I remember being able to do this using Twisted in Python 2.6 or so, using the same techniques.
At the time, the way to manipulate “deferred” results was to use the equivalent of “Promise.then”, but using generators as a quasi async/await seemed much more fluid.
I’m not sure what this gives you over actual async/await though, other than being an interesting thing to look at?
- masklinn 2y agoPython's plans for async was originally to use generators (that's the original reason for `yield from` IIRC: an async function may need to yield / await multiple times before it "completes" and returns a value). Ultimately async was introduced because: - mixing async-generators and sync-generators was extremely confusing and difficult to wrap your way around especially if you needed to nest them (e.g. a generator yielding awaitables) - lots of statements may need async for which generators are inconvenient and require manual desugaring and ad-hoc protocols with pure generators most notably asynchronous iterables