🌲 Timber - Javascript tools
This library provides helper tools used by the Javascript logger.
Tools
makeThrottle<TFunc>(max: number)
Returns a throttle
higher-order function, which wraps an async
function, and limits the number of active Promises to max: number
The throttle
function has this signature:
throttle(fn: TFunc): (...args: TFuncArg[]) => Promise<TFuncArg>
Usage example
import Timber from "@timberio/logger";
import { makeThrottle } from "@timberio/tools";
const timber = new Timber("apiKey");
const throttle = makeThrottle(2);
const pipeline = async log =>
new Promise(resolve => {
setTimeout(() => resolve(log), 2000);
});
timber.addPipeline(throttle(pipeline));
const promises = [];
for (let i = 0; i < 10; i++) {
promises.push(timber.log({ message: `Hello ${i}` }));
}
void (async () => {
void (await promises);
})();