Skip to content
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

Iterator Support for large globs #30

Open
rijnhard opened this issue Oct 11, 2018 · 4 comments
Open

Iterator Support for large globs #30

rijnhard opened this issue Oct 11, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@rijnhard
Copy link

Hi

Consider a method where the return object could be an Iterator or AsyncIterator so that large file globs (as in huge numbers of files) are supported.

@terkelg
Copy link
Owner

terkelg commented Oct 20, 2018

Is this to avoid blocking the main thread and what would such implementation look like?

@rijnhard
Copy link
Author

rijnhard commented Nov 6, 2018

Theres a few things involved here @terkelg

There are better implementations then what I did, this just so happened to have been fine for my use case.
In my local implementations, I used fast-glob and adapted a stream into an async iterator using the stream-to-async-iterator library.

Concerns:

  • async iteration isn't standardised by TC39 yet
  • libuv doesn't quite support it yet, and thus node readdir doesn't either.
  • do we need a sync iterator? Is it beneficial or even possible? (sync iterators are already standardised)

Notes:

  • From Node 10 - anywhere where streams are supported we can support async iteration
  • streams can be adapted into async iterators

Usage:

import fglob from 'fast-glob';
import StreamIteratorAdapter from 'stream-to-async-iterator';

async function process(dirglob ,globOptions) {
    const stream = fglob.stream(dirglob, globOptions),
        iterator = new StreamIteratorAdapter(stream);

    for await (const stat of iterator) {
    	// processes items individually allowing us to handle massive glob lists without hitting resource limits
    }
}

@terkelg
Copy link
Owner

terkelg commented Nov 6, 2018

Thanks for elaborating. This seems a bit complex. Is it possible add as an extension/wrapper around tiny-glob?

@terkelg terkelg added the enhancement New feature or request label Nov 6, 2018
@rijnhard
Copy link
Author

rijnhard commented Nov 6, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants