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

Feature request: early exit for sync implementation #225

Open
joscha opened this issue Sep 4, 2019 · 4 comments
Open

Feature request: early exit for sync implementation #225

joscha opened this issue Sep 4, 2019 · 4 comments
Assignees
Labels
Type: Enhancement Type: Need More Upvotes The functionality is useful, but it is unclear how much it is in demand. Vote.

Comments

@joscha
Copy link

joscha commented Sep 4, 2019

Currently it is not possible to stop a sync glob task. Let's say I run a glob to see if any file exists (similar to Array.some()) then I currently have to do:

fg.sync('pattern').length > 0

but it means that I still create the result. Ideally I would be able to:

fg.sync('pattern', { maxMatches: 1 }).length === 1

where .sync would exit once it has found maxMatches matches.

@mrmlnc mrmlnc self-assigned this Sep 4, 2019
@joscha
Copy link
Author

joscha commented Sep 4, 2019

I just stumbled across https://github.com/micromatch/glob-fs#middleware-examples which has the notion of a middleware, the above could also be implemented in that way, e.g.:

fg.sync('pattern', {
  middleware: (matchedFile, abort) => {
    if (foundWhatWeareLookingFor) {
	  abort(); // this is the last iteration, `fg.sync` will return after this middleware
    }
    // acts like a filter, returning `true` means we want to include the match
    return true;
  }
});

which would be more flexible but also a fair bit more complex.

@joscha
Copy link
Author

joscha commented Oct 31, 2019

@mrmlnc would you accept a pull request for this feature?

@mrmlnc
Copy link
Owner

mrmlnc commented Nov 2, 2019

Now it just looks like the functionality is beyond the scope of this package. Perhaps in the future we should think about hooks inside the fs.walk package.

What problem are you trying to solve? Config search?

The maxMatches option right now look better.

@joscha
Copy link
Author

joscha commented Nov 2, 2019

Implementing maxMatches sounds great. The reason I need it is because I am searching for the existence of at least one of a specific type of file.

joscha added a commit to joscha/fast-glob that referenced this issue Nov 5, 2019
This introduces a new option `maxMatches` which can be used to limit the
number of matches that fast-glob returns.

Closes: mrmlnc#225
@mrmlnc mrmlnc added the Type: Need More Upvotes The functionality is useful, but it is unclear how much it is in demand. Vote. label May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Type: Need More Upvotes The functionality is useful, but it is unclear how much it is in demand. Vote.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants