Home Reference Source
public class | source

Batcher

Extends:

events~EventEmitter → Batcher

Batcher provides a way to batch a lot of inputs into groups. It has two mechanisms to do this. The first mechanism is to set the 'batchSize' option to the maximum desired size of a single batch. When the buffer has reached this size it will flush the batch. The second option is to set the 'interval' option. If this option is set the batch will be flushed when either maximum batch size is reached or the interval has passed.

Constructor Summary

Public Constructor
public

constructor(options: IBatcherOptions)

Member Summary

Public Members
public
public
Private Members
private

_batch: *[]

private

If the interval options is set, this contains a reference for the set interval

Method Summary

Public Methods
public

close()

Stop the interval timer.

public

flush()

Flush the current batch.

public

write(item: unknown)

Write an item to the batch.

Public Constructors

public constructor(options: IBatcherOptions) source

Create a new Batcher and, if the 'interval' option is supplied, start the interval timer.

Params:

NameTypeAttributeDescription
options IBatcherOptions
  • optional
  • default: {batchSize: 5000, interval: 0}

Public Members

public batchSize: number source

public timeInterval: number source

Private Members

private _batch: *[] source

private _interval: number source

If the interval options is set, this contains a reference for the set interval

Public Methods

public close() source

Stop the interval timer.

public flush() source

Flush the current batch. If the batch is empty, this method does nothing.

public write(item: unknown) source

Write an item to the batch.

Params:

NameTypeAttributeDescription
item unknown