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

culvert

v0.1.2

Published

Channel for easy streaming of work between complex logics.

Downloads

4,597,064

Readme

Culvert

Channel for easy streaming of work between complex logics.

This is used in place of streams for CSP style flow. I use it in js-git for network and file streams.

Usually, you'll want to split sides to create a duplex channel.

var makeChannel = require('culvert');

var serverChannel = makeChannel();
var clientChannel = makeChannel();

function connect(host, port) {

  // This represents the server-side of the duplex pipe
  var socket = {
    put: serverChannel.put,
    drain: serverChannel.drain,
    take: cientChannel.drain
  };

  // When we want to send data to the consumer...
  socket.put(someData);

  // When we want to read from the consumer...
  socket.take(function (err, item) {});

  // Return the client's end of the pipe
  return {
    put: clientChannel.put,
    drain: clientChannel.drain,
    take: serverChannel.take
  };
}

If you want/need to preserve back-pressure and honor the buffer limit, make sure to wait for drain when put returns false.

// Start a read
socket.take(onData);

function onData(err, item) {
  if (err) throw err;
  if (item === undefined) {
    // End stream when nothing comes out
    console.log("done");
  }
  else if (socket.put(item)) {
    // If put returned true, keep reading
    socket.take(onData);
  }
  else {
    // Otherwise pause and wait for drain
    socket.drain(onDrain);
  }
}

function onDrain(err) {
  if (err) throw err;
  // Resume reading
  socket.take(onData);
}

If you're using continuables and generators, it's much nicer syntax.

var item;
while (item = yield socket.take, item !== undefined) {
  if (!socket.put(item)) yield socket.drain;
}
console.log("done");

Also the continuable version won't blow the stack if lots of events come in on the same tick.

makeChannel(bufferSize, monitor)

Create a new channel.

The optional bufferSize is how many items can be in the queue and still be considered not full.

The optional monitor function will get called with (type, item) where type is either "put" or "take" and item is the value being put or taken.

channel.put(item) -> more

This is a sync function. You can add as many items to the channel as you want and it will queue them up.

This returns true when the queue is smaller than bufferSize, it returns false if you should wait for drain.

channel.drain(callback)

Drain is a reusable continuable. Use this when you want to wait for the buffer to be below the bufferSize mark.

channel.take(callback)

Take is for reading. The callback will have the next item. It may call sync or it may be later.