Socket
Socket
Sign inDemoInstall

eventstapler

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eventstapler

Event Stapler is a utility to attach a collection of event listeners to an emitter in such a way that it is very easy to unbind them all later. All events attached via a staple can be detached in a single call, or after a specific event is fired by the e


Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Install size
3.38 kB
Created
Weekly downloads
 

Readme

Source

EventStapler

Event Stapler is a utility to attach a collection of event listeners to an emitter in such a way that it is very easy to unbind them all later. All events attached via a staple can be detached in a single call, or after a specific event is fired by the emitter.

Example

const eventStapler = require('.');
const stream = require('fs').createReadStream('./README.md');

const stapled = eventStapler(stream)
    .on('data', onData)
    .once('end', onEnd, null, stream)
    .once('error', onError, null, stream)
    .once('close', onClose)
    .releaseAfter('close')
    .releaseAfter('error');

function onData(chunk) {
    // process data
    console.log('CHUNK', chunk);
}

function onEnd(stream) {
    // handler is called with additional parameters provided at point of binding
    console.log('END');
    stapled.release(); // manually remove staple. all event handlers released.
}

function onClose() {
    console.log('CLOSE');
}

function onError(err) {
    // handle error.
    // don't worry about cleaning up old event listeners
    console.log('ERROR', err);
}

FAQs

Last updated on 15 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc