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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pull-limit

v1.2.2

Published

Limits the total number of items inside a through pull-stream.

Downloads

3

Readme

Build Status

pull-limit

Limits the total number of items inside a through pull-stream.

Defaults to 1. Once the limit has been reached, a newer item will be read only after a previous item has been drained.

Useful for limiting the rate of eager processing pipelines or for waiting for answers before sending more elements on a duplex transport, such as WebSockets.

Quick Examples

With a through pull-stream:

var pull = require('pull-stream')
var buffer = require('pull-eager-buffer')
var limit = require('pull-limit')

// Prints 0,0,1,1,2,2
pull(
  pull.count(2),
  pull.through(console.log),
  limit(buffer()),
  pull.through(console.log),
  pull.drain()
)

With a WebSocket, so that only one value is in transit and processed at a time. The next value is only sent when the result has been received. Otherwise, the socket would eagerly pull all the values:

var pull = require('pull-stream')
var ws = require('pull-ws')
var limit = require('pull-limit')

var server = ws.createServer(function (stream) {
  pull(
    stream, 
    pull.map(function (x) { return x.toLowerCase() }), 
    stream
)
}).listen(5000)

ws.connect('ws://localhost:5000', function (err, stream) {
  if (err) throw err
    
  // Prints 'A', 'a', 'B', 'b', 'C', 'c'
  pull(
    pull.values(['A', 'B', 'C']),
    pull.through(console.log),
    limit(stream),
    pull.through(console.log),
    pull.drain()      
  )
}) 

Signature

The following signature follows the js module signature syntax and conventions. All callbacks (parameters ending with 'cb') have the '(err, data)' signature.

limit: (stream: {
    sink: (streamRead: (abort, streamSinkCb)),
    source: (abort, cb)
}, ?n: number) =>
{
    sink: (read (abort, sinkCb)),
    updateLimit: (l: number),
    on('flow-rate', cb(rate, elapsedTimeInSec, n),
    source: (abort, cb)
}

Properties

  1. read is called once iff streamRead has been called.
  2. The first time streamRead is called, streamSinkCb will complete with the value coming from sinkCb as soon as it is available.
  3. For every subsequent streamRead call, streamSinkCb will only complete either after the stream closes or the number of elements sinked into stream.sink but not sourced by stream.source is below n, with n having a default value of 1.
  4. After updateLimit has been called, the n now has the l value.
  5. After n values have been processed, the 'flow-rate' event with the rate at which values have been trhrough, is emited.