Skip to content

Node module to throttle an incoming stream of objects by letting some of them pass through, and throwing away others.

Notifications You must be signed in to change notification settings

maurermax/node-object-throttle-skip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-throttle-skip

Node module to throttle an incoming stream of objects by letting some of them pass through, and throwing away others.

Within a specific timeframe a maximum number of x objects will pass.

What's this for?

If you want to get a rough idea of what this module is for, look as this fiddle.

http://jsfiddle.net/5afahLdf/11/show

Install

npm install object-throttle-skip

Usage

var Throttle = require('throttle');
var maxObjectCount = 30;
var maxObjectTimeFrameMs = 30000;
var t = new Throttle(maxObjectTimeFrameMs, maxObjectCount);

function incomingObject(obj) {
  // if you want to know what the probability for the next object will be use
  console.log(t.getProbability());
  // decide fate whether this incoming object should be propagated further
  return t.throttleObject(obj);
  // as an alternative you can do
  // if (t.throttle()) return obj;
}

More

  • Inn case you choose a negative window size all objects will be accepted

About

Node module to throttle an incoming stream of objects by letting some of them pass through, and throwing away others.

Resources

Stars

Watchers

Forks

Packages

No packages published