🌲 Timber - JS lib tools
Generic FIFO queue. Used by
makeThrottle to store pipeline functions to be executed as concurrent 'slots' become available. Provides fast retrieval for any primitive or object that needs ordered, first-in, first-out retrieval.
Used to store
.log() Promises that are being batched/throttled.
;// Interface representing a person// Create a queue to store `IPerson` objects;// Add a couple of records...q.push;q.push;// Pull values from the queue...while q.length
throttle higher-order function, which wraps an
async function, and limits the number of active Promises to
throttle function has this signature:
throttle(fn: T): (...args: InferArgs<T>) => Promise<InferArgs<T>>
;;// Create a new Timber instance;// Guarantee a pipeline will run a max of 2x at once;// Create a basic pipeline function which resolves after 2 seconds;// Add a pipeline which has been throttledtimber.addPipelinethrottlepipeline;// Add 10 logs, and store the Promises;for ; i < 10; i++void;
makeBatch(size: number, flushTimeout: number)
Creates a higher-order batch function aggregates Timber logs and resolves when either
size # of logs have been collected, or when
flushTimeout (in ms) has elapsed -- whichever occurs first.
Used internally by the
@timberio/core Base class to implicitly batch logs:
// Create a throttler, for sync operations;// Sync after throttling;// Create a batcher, for aggregating logs by buffer size/interval;this._batch = batcher;