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

Add a callback hook when throttled #44

Closed
dormeiri opened this issue Dec 4, 2023 · 2 comments · Fixed by #47
Closed

Add a callback hook when throttled #44

dormeiri opened this issue Dec 4, 2023 · 2 comments · Fixed by #47

Comments

@dormeiri
Copy link
Contributor

dormeiri commented Dec 4, 2023

I would like to observe every time I reach the throttling limit and get delayed.

I think I can achieve it by calling a callback function when getDelay() is greater than zero here:

timeoutId = setTimeout(execute, getDelay());

The callback function can be passed as one of the options in:

export default function pThrottle({limit, interval, strict}) {

I suggest something like this: onDelay: (info: { delay: number, queueSize: number }) => void | Promise<void>, WDYT?

I can open a PR if it helps.

Edit: I can live without passing the info to the callback, so this also works for my use-case: onDelay: () => void | Promise<void>

@sindresorhus
Copy link
Owner

What's the use-case?

@dormeiri
Copy link
Contributor Author

dormeiri commented Dec 5, 2023

I want to send a metric when delayed to analyze the performance of my app

I opened a suggestion PR just in case it is OK by you to add this functionality :)
#47

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

Successfully merging a pull request may close this issue.

2 participants