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

refactor: remove pLimiter code repetition #265

Closed

Conversation

iccicci
Copy link
Contributor

@iccicci iccicci commented Nov 19, 2024

Apart from when it is used to gather stats, pLimiter is always used with pLimiter.add(task, { throwOnTimeout: true }).

This PR add the limiter utility to remove this code repetition also increasing a bit the readability.

@@ -28,3 +28,6 @@ pLimiter.on('error', error => {
ratesLimiter.on('error', error => {
logger.warn(`ratesLimiter error`, error);
});

export const limiter = <T>(task: () => PromiseLike<T>) =>
pLimiter.add<T>(task, { throwOnTimeout: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure that the passed options are still configurable

@iccicci iccicci force-pushed the refactor/readability branch from d7c1eb5 to 92f02ec Compare November 19, 2024 12:00
@iccicci iccicci deleted the branch refactor/readability November 19, 2024 12:11
@iccicci iccicci closed this Nov 19, 2024
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 this pull request may close these issues.

2 participants