function injectAsyncRateLimitedCallback<TFn>(fn, options): (...args) => Promise<Awaited<ReturnType<TFn>> | undefined>;
Defined in: async-rate-limiter/injectAsyncRateLimitedCallback.ts:43
An Angular function that creates an async rate-limited version of a callback function. This function is essentially a wrapper around injectAsyncRateLimiter that provides a simplified API for basic async rate limiting needs.
This function provides a simpler API compared to injectAsyncRateLimiter, making it ideal for basic async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.
For advanced usage requiring features like:
Consider using the injectAsyncRateLimiter function instead.
TFn extends AnyAsyncFunction
TFn
AsyncRateLimiterOptions<TFn>
(...args): Promise<Awaited<ReturnType<TFn>> | undefined>;
...Parameters<TFn>
Promise<Awaited<ReturnType<TFn>> | undefined>
// Rate limit API calls
const makeApiCall = injectAsyncRateLimitedCallback(
async (data: ApiData) => {
const response = await fetch('/api/endpoint', {
method: 'POST',
body: JSON.stringify(data)
});
return response.json();
},
{
limit: 5,
window: 60000,
windowType: 'sliding',
}
);
// Use in event handler
const result = await makeApiCall(apiData);