Class Batcher<O, M>

Description

Tasks batcher

Features:

  • Group single tasks into batch request

Example

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { IBatcher, Batcher } from '@biorate/batcher';

const batcher: IBatcher = new Batcher<{ data: string }, { test: string }>();

batcher.register((tasks) => {
console.log(tasks);
// [
// [
// { data: 'one' },
// {
// resolve: [Function (anonymous)],
// reject: [Function (anonymous)],
// metadata: { test: 'one' }
// }
// ],
// [
// { data: 'two' },
// {
// resolve: [Function (anonymous)],
// reject: [Function (anonymous)],
// metadata: { test: 'two' }
// }
// ],
// [
// { data: 'three' },
// {
// resolve: [Function (anonymous)],
// reject: [Function (anonymous)],
// metadata: { test: 'three' }
// }
// ]
// ]
});
batcher.add({ data: 'one' }, { test: 'one' });
batcher.add({ data: 'two' }, { test: 'two' });
batcher.add({ data: 'three' }, { test: 'three' });

Type Parameters

Hierarchy

  • Batcher

Implements

Constructors

Properties

callback: ((tasks) => void)

Type declaration

    • (tasks): void
    • Parameters

      Returns void

count: number = 100
stamp: number = ...
tasks: [O, ITask<M>][] = []
timeout: number = 100
unique: Set<string | symbol> = ...

Accessors

Methods

Generated using TypeDoc