2 ms·
I know it's an area of some debate, but at least to me, greenlets are easier to write and understand than callbacks, by an order of magnitude. Greenlets work e
by et1337 11y ago
I know it's an area of some debate, but at least to me, greenlets are easier to write and understand than callbacks, by an order of magnitude.
Greenlets work especially well with Python's "with" statement. You can have a database pool like this:
with (yield from pool.connection()) as conn:
users = yield from conn.query('select * from users')
for user in user: ...
Now your database connection is only locked up inside the "with" statement, and the whole thing is asynchronous even though it's written in a synchronous style.
- rubiquity 11y agoYou can do this in Ruby with Fibers and people have been doing so for the past 6 or 7 years.