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-spawn

v0.0.7

Published

Spawn pull streams into substreams.

Downloads

7

Readme

pull-spawn

Spawn pull streams into substreams.

Usage

spawn(throughCreator, ?onSpawn)

Creates an isolated execution context around the through stream. If the through stream ends with an error, spawn will recreate the through stream.

####args

  • throughCreator - A callback that should return the through stream.
  • onSpawn - Optional callback to trigger when spawns.

####example

var pull = require("pull-stream");
var spawn = require("pull-spawn");

pull(
  pull.count(20),
  spawn( function () {
    return function (read) {
      return function (end, cb) {
        if (Math.round(Math.random() * 3) == 0) { return cb(new Error("random error")); }
        read(end, cb);
      }
    }
  }, function() {console.log("spawning")}),
  pull.log()
)

spawn.isolate(throughCreator)

Similar to spawn, but will spawn a through on each read. Usefull, when you want to extract one read into multiple writes.

throughCreator will get data as argument. data is the read result.

example

var pull = require("pull-stream");
var isolate = require("pull-spawn").isolate;

pull(
  pull.values([1, 2, 3]),
  isolate(function (num) {
    console.log("isolating", num);
    return pull(
      pull.map(function (n) {return n * num})
    )
  }),
  pull.log()
)

spawn.fork(sink)

Forks readable stream into another Sink other than the main sink.

Respects back-pressure: reads from upstream, only once both sinks are ready to read.

The forked stream will abort if an error ocurred on the main stream. The main stream won't abort if the forked stream was aborted.

args

sink, as it sounds, should be a sink stream.

pull(
  pull.count(10),
  spawn.fork(pull.drain(console.error)),
  pull.log()
)

You can specify several sinks:

pull(
  pull.count(10),
  spawn.fork(
    sink1,
    sink2
  ),
  pull.log()
)

Which is eventually similar to:

pull(
  pull.count(10),
  spawn.fork(sink1)
  spawn.fork(sink2)
  pull.log()
)

sink can also be an array of sinks.

example

var pull = require("pull-stream");

var fork = require("pull-spawn").fork;

var slowMap = pull.asyncMap( function (d, done) {
  setTimeout( function () {
    done(null, d);
  }, 1000)
})

pull(
  pull.values([1,2,3,4,5]),
  fork(
    pull(pull.map(function (d) {return d*10}), pull.log()),
    pull(slowMap, pull.map(function () {return "slow fork"}), pull.log())
  ),
  pull.log()
)

advanced usage: fork a through

var read = someSourceStream;
var s = spawn.fork(through)(read);

// main stream
pull(
  s,
  pull.log();
)

// forked stream
pull(
  s.child,
  pull.log();
)

As you can see, if you fork a pull-stream manually, you'll be able to access pipedStream.child and read from it.

spawn.observe(sink)

observe is exactly the same as fork, with one difference. It would read as fast as the main sink reads. Which means that if the observer is a slow sink, it's data will be buffered.

If the observer is faster than the main sink, it will wait the main sink to read.

Everything else, is exactly the same (including the child property).

example

var pull = require("pull-stream");

var observe = require("pull-spawn").observe;

var slowMap = pull.asyncMap( function (d, done) {
  setTimeout( function () {
    done(null, d);
  }, 1000)
})

pull(
  pull.values([1,2,3,4,5]),
  observe(
    pull(pull.map(function (d) {return d*10}), pull.log()),
    pull(slowMap,pull.map(function () {return "observed"}), pull.log())
  ),
  pull.log()
)

spawn.consume(sink)

Similar to observe and fork with one main difference. It will pull data from upstream as fast as the fastes consumer (could be the main consumer, or the alternative consumer). The stream will abort consuming data after the last consumer was terminated.

install

With npm do:

npm install pull-spawn

license

MIT