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

Allow abort glob progress #435

Open
otakustay opened this issue Jan 10, 2024 · 0 comments
Open

Allow abort glob progress #435

otakustay opened this issue Jan 10, 2024 · 0 comments

Comments

@otakustay
Copy link

Environment

  • OS Version: macOS 14.2.1
  • Node.js Version: 20.10.0

Reference: sindresorhus/globby#261

  1. Can't stop glob from working when timed out or 1 file is found
  2. Not easy to check "at least 1 file matches glob patterns"

Code sample

Have a AbortSignal option to stop stop glob in progress.

const signal = AbortSignal.timeout(200);
try {
  return await fg.glob(patterns, {signal});
}
catch {
  return [];
}

Or have a globExists matching the first file.

async function globExists(patterns, options) {
    const controller = new AbortController();
    for await (const entry of fg.globStream(patterns, {...options, signal: controller.signal})) {
        controller.abort();
        return entry;
    }
}
@mrmlnc mrmlnc added this to the 4.0.0 milestone Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants