Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@timberio/tools

Package Overview
Dependencies
Maintainers
5
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@timberio/tools

Javascript logging tools

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
656
increased by18.2%
Maintainers
5
Weekly downloads
 
Created
Source

🌲 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";

// Create a new Timber instance
const timber = new Timber("apiKey");

// Guarantee a pipeline will run a max of 2x at once
const throttle = makeThrottle(2);

// Create a basic pipeline function which resolves after 2 seconds
const pipeline = async log =>
  new Promise(resolve => {
    setTimeout(() => resolve(log), 2000);
  });

// Add a pipeline which has been throttled
timber.addPipeline(throttle(pipeline));

// Add 10 logs, and store the Promises
const promises = [];
for (let i = 0; i < 10; i++) {
  promises.push(timber.log({ message: `Hello ${i}` }));
}

void (async () => {
  void (await promises); // <-- will take 10 seconds total!
})();

FAQs

Package last updated on 20 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc