-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create async iterator version of _lsdir() #670
Conversation
Please add a docstring to Do you think there should also be a sync version of this, |
I don't think it makes a lot of sense to wrap |
It may be inefficient, but perhaps still desirable for a case where the caller only wants files in the first few pages out of many. |
Would it be possible to make |
As written, maybe (but all async methods are underscored); but actually DVC plans to call it, right? Which suggests that it is useful, and a sync version of it would be too. I don't actually know whether you can simply wrap an async iterator and get a sync iterator as you would expect for a normal method. If yes, do it; if no, then it's probably too much effort. |
For now this will be used in another project related to dvc and for that purpose, we could use it as a hidden method and that was my understanding. Maybe @rlamy could clarify. Maybe it makes sense to have an official |
@efiop Indeed, for our (dvc-related) current purposes, it's fine to use a private hidden method. Having def iterdir(self, ...):
aiter = self.iterdir(...)
while True:
try:
entry = sync(self.loop, aiter.__anext__)
yield entry
except StopAsyncIteration:
break |
OK, going to merge this as an internal implementation detail for now, and we can consider more visible changes at another time. |
When dealing with large directories, using
_ls()
/_lsdir()
forces us to wait until all the contents of the directory have been received, which can take a significant amount of time. This PR creates an_iterdir()
async iterator which allows the results to be handled as soon as they're received from the network.