westonpace opened a new pull request #10968:
URL: https://github.com/apache/arrow/pull/10968
Any type that wants to participate in an asynchronous nursery must extend
`AsyncCloseable`. These types can then communicate work that needs to be
finished before the nursery can close in several ways.
* Provide an overridden DoClose method that returns a future indicating
when work is done
* Add children
* Add dependent tasks
An AsyncCloseable is _finished_ when the future returned by DoClose has
completed and any dependent tasks have completed and all of its children are
_finished_.
An object will not be destroyed until it is _finished_. This means you can
safely capture `this` (and references to parent state).
For a real world example take a look at `dataset_writer.cc` in #10955 which
uses an async nursery to capture a dataset writer, it's children (directory
queues) and grandchildren (file queues). File queues can be evicted from the
nursery early. The dataset writer is not "finished" until all queued files
have been written. `this` and `&` captures are used freely throughout the code.
Cons:
* It's a bit tricky to get it working with the pimpl pattern but
`NurseryPimpl` helps here
* There are a lot of "nursery-like" objects starting to pop up (IOContext,
ExecContext, cancellation tokens, ...) and we may want to consolidate at some
point
* Doesn't really get rid of shared_ptr's so much as it hides them. Objects
owned by the nursery must be shared_ptr. Can use "dependent tasks" to avoid
creating a shared_ptr however.
ToDo:
* Investigate simply passing the nursery down by reference into all of the
objects instead of bothering with the parent / child relationships and
requiring inheritance.
* Fix up some of the APIs with some template hackery (e.g. merging
`RunInNursery` and `RunInNurserySt`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]