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

async-queue-stream

v0.1.3

Published

Stream using async.queue under the hood.

Downloads

43

Readme

async-queue-stream

Wrapper for through stream to use async.queue under the hood.

It takes an asynchronous function and queue stream chunks. Then the queue executes the asynchronous function up to the concurrency threshold.

Any error will be emitted to opts.error_event event. By default, the stream will not stop on error; this can be configured via opts.stop_on_error.

Install

  1. Install Node.js

  2. Run: npm install async-queue-stream

API

asyncqueue(write_fn [[, end_fn], options])

Arguments

  • write_fn(data, callback) - an asnynchronous function that will be wrapped into a through stream

    data is the queued stream chunk.

    There are three ways to invoke callback:

    • callback(null, transformedData) - emit data
    • callback(error) - emit error
    • callback() - drop data (don't emit to next stream)
  • end_fn() - a function that will be invoked when no more data will be provided.

  • options - an object containing options

    • options.concurrency - concurrency argument to async.queue. Default: 1

    • options.error_event - event name used to emit the error from callback via the asynchronous function. Default: 'failure'

    • options.stop_on_error - boolean value for asyncqueue to stop queuing any more stream chunks if callback via the asynchronous function has emitted an error. Default: false

      Note: Any tasks already executed will be able to complete.

Example

var es = require('event-stream');
var qasync = require('queue-async-stream');

// something that returns stream using queue-async-stream internally
var plugin = function(filter, filter_func) {

    if(filter_func == void 0)
        filter_func = function(n) { return n; };

    return qasync(function (data, cb) {

        if(filter_func(data) == filter) {
            setTimeout(function() {

                return cb(new Error(filter+''));
            }, 1000);
            return;
        }

        if(data === 2) {
            setTimeout(function() {
                return cb(null, data);
            }, 2000);
            return;
        }

        console.log('caught in plugin: ' + data)
        return cb(null, data);

   }, {concurrency: 2});
};


es.readArray([1,2,3,4,5])
    .pipe(plugin(3))
        .on('failure', console.log)
    .pipe(es.through(function(n) {

        console.log('caught in es.through: ' + n);

        this.emit('data', n);
    }));
/**
Output:
    caught in plugin: 1
    caught in es.through: 1
    [Error: 3]
    caught in plugin: 4
    caught in es.through: 4
    caught in plugin: 5
    caught in es.through: 5
    caught in es.through: 2


With stop_on_error:true, output is:
    caught in plugin: 1
    caught in es.through: 1
    [Error: 3]
    caught in es.through: 2
 */

To Do

  1. Be able to pass opts/hooks to async.queue (e.g. drain, empty, etc)

License

MIT. See LICENSE file.