Docs
Cloudflare
Railway
CodeRabbit
WorkOS
SerpAPI
AG Grid
OpenRouter
Netlify
Clerk
Electric
Prisma
Sentry
Unkey
Cloudflare
Railway
CodeRabbit
WorkOS
SerpAPI
AG Grid
OpenRouter
Netlify
Clerk
Electric
Prisma
Sentry
Unkey
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Rate Limiter API Reference

injectAsyncRateLimitedCallback

Function: injectAsyncRateLimitedCallback()

ts
function injectAsyncRateLimitedCallback<TFn>(fn, options): (...args) => Promise<Awaited<ReturnType<TFn>> | undefined>;
function injectAsyncRateLimitedCallback<TFn>(fn, options): (...args) => Promise<Awaited<ReturnType<TFn>> | undefined>;

Defined in: angular-pacer/src/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:

  • Manual cancellation/reset
  • Access to execution counts
  • Error handling callbacks
  • Retry support

Consider using the injectAsyncRateLimiter function instead.

Type Parameters

TFn

TFn extends AnyAsyncFunction

Parameters

fn

TFn

options

AsyncRateLimiterOptions<TFn>

Returns

ts
(...args): Promise<Awaited<ReturnType<TFn>> | undefined>;
(...args): Promise<Awaited<ReturnType<TFn>> | undefined>;

Parameters

args

...Parameters<TFn>

Returns

Promise<Awaited<ReturnType<TFn>> | undefined>

Example

ts
// 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);
// 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);