Docs
CodeRabbit
Cloudflare
AG Grid
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Batcher API Reference

injectBatchedCallback

Function: injectBatchedCallback()

ts
function injectBatchedCallback<TValue>(fn, options): (item) => void;

Defined in: batcher/injectBatchedCallback.ts:40

An Angular function that creates a batched version of a callback function. This function is essentially a wrapper around injectBatcher that provides a simplified API for basic batching needs.

The batched function will collect items and process them in batches based on the configured conditions (maxSize, wait time, etc.).

This function provides a simpler API compared to injectBatcher, making it ideal for basic batching needs. However, it does not expose the underlying Batcher instance.

For advanced usage requiring features like:

  • Manual flushing
  • Access to batch state
  • State tracking

Consider using the injectBatcher function instead.

Type Parameters

TValue

TValue

Parameters

fn

(items) => void

options

BatcherOptions<TValue>

Returns

ts
(item): void;

Parameters

item

TValue

Returns

void

Example

ts
// Batch API calls
const batchApiCall = injectBatchedCallback(
  (items) => {
    return fetch('/api/batch', {
      method: 'POST',
      body: JSON.stringify(items)
    });
  },
  { maxSize: 10, wait: 1000 }
);

// Items will be batched and sent together
batchApiCall('item1');
batchApiCall('item2');