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

Async methods #1

Open
sindresorhus opened this issue Jun 3, 2022 · 4 comments
Open

Async methods #1

sindresorhus opened this issue Jun 3, 2022 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

I think it could be useful with async methods too, when you not only want to prevent abuse, but also don't want the regex matching to block other work, which can be important in a server context.

We could do the matching on a worker thread and then send the result back to the main process. This should be possible on both Node.js and the browser.

This is not something I plan to work on, but a good pull request would be welcomed if you need this.

See https://github.com/sindresorhus/crypto-hash/blob/main/index.js for an example of how it could be done.

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Jun 3, 2022
@Richienb
Copy link
Contributor

  1. Create worker
  2. Run task on worker.
  3. If task doesn't complete before the timeout, terminate the worker and restart it with every other task.

@Richienb
Copy link
Contributor

Revised:

  1. Create worker
  2. Run task on worker
  3. Close worker

Timeout shall apply to the worker and not the function executed by it.

@sindresorhus
Copy link
Owner Author

I made something for this: https://github.com/sindresorhus/make-asynchronous

@fabiospampinato
Copy link

fabiospampinato commented Nov 4, 2023

A nice thing about the async approach is that the worker can be terminated at any time, so it could be used to stop regexes in any environment.

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

No branches or pull requests

3 participants