Socket
Book a DemoInstallSign in
Socket

event-regulator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-regulator

commonjs module for managing event subscriptions

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

Event Regulator

Small module that exports a EventRegulator object which is used for creating and tracking event subscriptions as groups. When a terminal event happens, all event subscriptions are cleaned up ensuring deterministic behavior inside your system.

Example


// Subscribe to events on the socket, if error or close is emitted
// call onError or onClose and then remove all event listeners managed
// by this instance of the regulator object
var regulator = new EventRegulator([
  [mysocket, 'data', onData],
  [mysocket, 'connect', onConnect],
  [mysocket, 'timeout', onTimeout],
  [mysocket, 'error', onError, true], // terminal event
  [mysocket, 'close', onClose, true] // terminal event
]);

function onData (data) {
  // If we're going away, then destroy the regulator (removing all listeners)
  // and close the socket
  if (data === 'bye now') {
    regulator.destroy();
    mysocket.end('ok');
  }
}

Install

You can install the event-regulator module from npm using:

npm install event-regulator

License

MIT Licensed, full license in the LICENSE file.

Keywords

events

FAQs

Package last updated on 16 Jan 2016

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.