npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rx-op-lossless-throttle

v1.0.2

Published

Lossless rate limiting operator for RxJS

Readme

Description

Lossless throttle behavior for RxJS.

losslessThrottle(delay, scheduler)

Re-emits ALL input events separated by at least delay using optional scheduler (async by default)

Marble diagram

IN:  a----b-c------def------gh|
OUT: a----b---c----d---e---f---g---(h|)

Installation

Use npm or yarn

npm install --save rx-op-lossless-throttle
yarn add rx-op-lossless-throttle

Usage

throttleOp(windowSizeInMsOrConfig, scheduler = null)

Config is a hash with the following keys:

  • windowSize [number] - size of the window in ms (or scheduler frames);
  • bufferSize [number|null] - limit on the number of buffered items (null - no limit);
  • raiseOnOverflow [boolean] - true - operator raises an error on overflow; false - incoming items are silently discarded on overflow.

Note that with bufferSize: 0 and raiseOnOverflow: false the behavior will match the standard throttle operator.

For example:

import { throttleLet, throttleOp } from "rx-op-lossless-throttle";

out$ = in$.let(throttleLet(100));
out$ = in$::throttleOp(100);
out$ = in$::throttleOp({
  windowSize: 100,
  bufferSize: 10,
  raiseOnOverflow: true
})

or, if you're feeling lucky:

Observable.prototype.losslessThrottle = throttleOp;
out$ = in$.losslsssThrottle(100);

Use case

I had a piece of ETL code which did something like this:

producer API call, returns paginated results ->
 several batches of ~100 items ->
   basic processing ->
     stream of independent items ->
       consumer API, accepts a single item

See the problem here? Yes, one producer API call would result in 100 calls to the consumer API.

Now, in a perfect world:

  • the consumer API would have proper throttling and it would scale to handle load spikes transparenty;
  • or the consumer API would return a proper error code we'd be able to detect and re-try submission;
  • or the consumer API would allow us to submit data in batches;
  • or something else which wouldn't require us to deal with this problem in ETL logic.

The problem is we don't live in a perfect world and we don't have control over the consumer. On the other side, separating consumer API calls by 50-100ms eliminated the "consumer chokes on the spike" problem. By any means, it's not a perfect solution, but it works and gives time to find a better one.

Questions

But isn't it a foot gun which may result in unbound memory growth

Absolutely correct. You may (and you probably should) limit the buffer size with bufferSize configuration to prevent OOM. There's no default limit as I cannot guess what kind of data you're processing, how much memory you can spare on the buffer and how important the data is.

RxOp collection