New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fair-share

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fair-share

Share processor time between async functions

1.0.4
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

fair-share

Node.js module. Interrupts async functions after a short time span (default is 10 ms) so that other code in waiting in the event loop queue can run in between coming back to the function. Thus making it possible for several aync functions to fairly share processor time.

Usage

npm install fair-share

Example

FairShare = require('fair-share');

async function func(){
  // msBeforeShare is optional, defaults to 10 ms
  let share = new FairShare({msBeforeShare: 5});
  let randomNumberArray = [];
  // a loop that is time consuming
  while(randomNumberArray.length < 1000000){
    randomNumberArray.push(Math.random());
    // interrupts the loop after 5 ms
    // thus sharing/not-blocking other code
    share.do();
  }
  // there are stats about how many interrupts
  // that were done to be had if you want to
  console.log(share.stats);
}

Example stats

{ 
  "iterations": 1000000,
  "pauses": 22,
  "cyclesBetweenInterrupts": 45455
}

FAQs

Package last updated on 20 Aug 2017

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