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

@mixmaxhq/invoke-fraction

Package Overview
Dependencies
Maintainers
13
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mixmaxhq/invoke-fraction

Partition invocations across a set of functions based on defined fractions.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
13
Created
Source

invoke-fraction

Partition invocations across a set of functions based on defined fractions.

Example

// Randomly invoke one of following arrow functions based on the given fraction.
// e.g. it'll invoke the first function ~10% of the time if called repeatedly.
invokeFraction([
  [0.1, () => console.log('10%')],
  [0.3, () => console.log('30%')],
  // The number here doesn't matter, provided it's >0, as it's the last partition.
  [0.6, () => console.log('60%')],
]);

The invokeFraction function also supports a defaultHandler parameter, which stands in for the last item of the handlers array. Note that this is the recommended way to avoid letting the last item in the handlers array be invoked for the remaining partition, rather than the defined fraction.

invokeFraction([
  [0.1, () => console.log('10%')],
  [0.3, () => console.log('30%')],
], () => console.log('60%'));

The invokeFraction function will return the value returned by the function invoked, so you can use this with promises and async/await.

Keywords

FAQs

Package last updated on 30 Jun 2021

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