The Google cloud ndb documentation doesn't say much about async operations.
In the old days, I would do this
@ndb.toplevel
@flask.route('/', methods=['GET'])
def page():
for x in xxx:
ndb.put_multi_async([...])
return 'Done', 200
and the toplevel decorator would make sure that my async puts were done.
How do I do this with the latest cloud ndb?
The cloud ndb docs for toplevel say
Use of this decorator is largely unnecessary, as you should be using context() which also flushes pending work when exiting the context.
but it would be helpful to have more clarity. When would it still be necessary to use toplevel?
As stated in the documentation for the NDB Asynchronous Operation:
This was convenient when using the NDB Client Library with Python 2, as you've said:
Nowadays using the Cloud NDB library, as shown in this answer,
That is why the documentation says that the use of toplevel decorator
because context decorator replaced it and it will
As referred in the
ClientNDB documentation:Finally, as referred in the
ndbMigration notes: