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

@brick-city/iterable-emitter

v0.0.5

Published

This utility turns a streaming emitter into an iterable, buffers the stream of events, and will pause & resume the emitter.

Downloads

8

Readme

iterable-emitter

Use this class to create an object that monitors an emitter and allows the events of the emitter to be asynchronously iterated.

Events are queued so they can be iterated at a different rate than what they are emitted at. For instance an ETL process that extracts data faster than it can be loaded asynchronously to a remote destination.

The queue has a high water mark that can limit memory requirements for the queued events. Once the high water mark is reached, the emitter will be paused to stop the flow of events. Once the events have been drained to the low water mark, the emitter will be resumed.

Table of Contents

Installation

npm install --save @brick-city/iterable-emitter

Usage

General

new IterableEmitter (emitter:Emitter, options:[iterableEmitterOptions](#options))

Returns:IterableEmitter

import IterableEmitter from '@brick-city/iterable-emitter'
import Request from 'tedious';

request = new Request("select i.item, i.description from dbo.item i", function(err, rowCount) {
  ...
});

const options = {
    dataEvent: 'row',
    resolutionEvent: ['done', 'doneInProc', 'doneProc'],
    pauseMethod: 'pause',
    resumeMethod: 'resume',
}

const iterableRequest = new IterableEmitter (request, options )

connection.execSql(request);

try {

    for await (const row of iterableRequest) {

      .....
        Do something awesome!
      .....

    }

} catch (e) { console.log(e); }

Options

  • dataEvent: 'row' (string, required) - The name of the event that provides the stream of data.

  • resolutionEvent: 'done' (string | array[string], required) - An emission of the resolutionEvent(s) will end the iterable once the queue is drained.

  • rejectionEvent: 'error' (string | array[string], defaults to 'error') An emission of the rejectionEvent(s) will end the iterable immediately (queued events are cleared) and the iterable rethrows the caught error.

  • highWaterMark:1000 (integer, defaults to 1000) - The number of events to queue prior to pausing the emitter.

  • lowWaterMark: 500 (integer, defaults to 500) - Once a paused iterable has been drained to this level the emitter will be resumed.

  • initializeBuffer:true (boolean, defaults to true) Initialize the buffer for highWaterMark entries.

  • pauseMethod: (string, conditionally optional) - method on the emitter that will pause the stream of dataEvents. It will be called without arguments when the total queued events have reached the highWaterMark. It will be called repeatedly if the stream continues. Either pauseMethod or pauseFunction must be specified, but not both.

  • pauseFunction: (function<void>, conditionally optional) - A function to be called to pause the stream of dataEvents. It will be called without arguments when the total queued events have reached the highWaterMark. It will be called repeatedly if the stream continues. Either pauseMethod or pauseFunction must be specified, but not both.

  • resumeMethod: (string, conditionally optional) - method on the emitter that will resume the stream of dataEvents after being paused. It will be called without arguments on a paused emitter once the buffer has been drained to the lowWaterMark. Either resumeMethod or resumeFunction must be specified, but not both.

  • resumeFunction: (function<void>, conditionally optional) - A function to be called to resume the stream of dataEvents on a pause emitter. It will be called without arguments on a paused emitter once the buffer has been drained to the lowWaterMark. Either resumeMethod or resumeFunction must be specified, but not both.

  • preFilter: ()=>{} (function<boolean>, optional) - The arguments supplied to the dataEvent event handler will be pass on to the preFilter function. Returning true will push the event results on the buffer, false and it will be ignored

  • transform: ()=>{} (function<any>, optional) - The arguments supplied to the dataEvent event handler will be passed to the transform function, the results of which will be pushed on the buffer.

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

License

MIT License