A promise-aware throttling library that rate-limits function calls without discarding them, ideal for API interactions.
p-throttle is a JavaScript library that throttles promise-returning, async, and normal functions by rate-limiting calls without discarding them. It solves the problem of managing API rate limits by queuing all calls and executing them within configured limits, ensuring no calls are lost.
JavaScript developers working with external APIs, rate-limited services, or any scenario where controlled function execution is needed to avoid overwhelming systems.
Developers choose p-throttle for its guarantee that all calls are executed, its flexible configuration including weight-based throttling, and its support for modern browser APIs like AbortSignal and WeakRef.
Throttle promise-returning & async functions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
All function calls are queued and executed without loss, as the README emphasizes this is crucial for API interactions where avoiding call loss is a priority.
Offers configurable limit and interval, strict throttling algorithm, and weight-based throttling for cost-aware rate limiting, demonstrated in the API options and examples.
Integrates with AbortSignal to cancel pending executions, providing control over throttled calls, as shown in the signal option example where aborted calls are rejected.
Provides queueSize and onDelay callback for implementing fallback strategies, useful for managing high-load scenarios, as illustrated in the queue management example.
Requires modern browsers with WeakRef and FinalizationRegistry (Chrome 84+), limiting use in older environments without polyfills, as noted in the README's browser section.
The strict throttling algorithm is more resource-intensive, which might impact performance in high-frequency applications, as admitted in the README's strict option description.
While it queues calls for execution, it doesn't automatically handle retries or errors during execution, leaving error management entirely to the user, which isn't addressed in the features.