A. Jesse Jiryu Davis
2018-06-26 13:14:10 UTC
Hi friends. I'm preparing version 2.0 of Motor, my async Python driver for
MongoDB. Version 2.0 is an opportunity for me to delete a lot of deprecated
Motor APIs and clean up the internal code.
One of Motor's messiest problems is how to support Futures alongside its
original callback-based API:
# Old-fashioned:
def callback(result, error):
if error:
print(error)
else:
print(result)
def func():
motor_client.db.collection.insert_one({'_id': 1}, callback=callback)
# Modern:
@gen.coroutine
def func():
result = yield motor_client.db.collection.insert_one({'_id': 1})
# Contemporary:
async def func():
result = await motor_client.db.collection.insert_one({'_id': 1})
If I remove the callback API and I only support Futures, then the Modern
and Contemporary styles will still work but the Old-fashioned code will
break. Users who want callbacks could use Future.add_done_callback, but
their code would be very different from today, and slower.
What's the opinion on this list? Are callbacks completely outdated, or do
you think some async programmers still rely on them?
MongoDB. Version 2.0 is an opportunity for me to delete a lot of deprecated
Motor APIs and clean up the internal code.
One of Motor's messiest problems is how to support Futures alongside its
original callback-based API:
# Old-fashioned:
def callback(result, error):
if error:
print(error)
else:
print(result)
def func():
motor_client.db.collection.insert_one({'_id': 1}, callback=callback)
# Modern:
@gen.coroutine
def func():
result = yield motor_client.db.collection.insert_one({'_id': 1})
# Contemporary:
async def func():
result = await motor_client.db.collection.insert_one({'_id': 1})
If I remove the callback API and I only support Futures, then the Modern
and Contemporary styles will still work but the Old-fashioned code will
break. Users who want callbacks could use Future.add_done_callback, but
their code would be very different from today, and slower.
What's the opinion on this list? Are callbacks completely outdated, or do
you think some async programmers still rely on them?
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.