Socket
Socket
Sign inDemoInstall

emittery

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emittery

Simple and modern async event emitter


Version published
Weekly downloads
20M
decreased by-15.23%
Maintainers
2
Weekly downloads
 
Created

What is emittery?

The emittery npm package is an asynchronous event emitter library. It allows you to emit and listen for events in a way that is not tied to the DOM and is more flexible than the native Node.js EventEmitter. It supports async iteration of events, namespaced events, and ensures that listeners are called in the order they were added.

What are emittery's main functionalities?

Emitting and listening to events

This feature allows you to create an event emitter, listen for events, and emit events with data. Listeners are invoked with the data passed to `emit`.

{"const Emittery = require('emittery');\nconst emitter = new Emittery();\n\nemitter.on('event', data => {\n  console.log(data);\n});\n\nemitter.emit('event', 'some data');\n//=> 'some data'"}

Asynchronous event emission

This feature allows you to wait for all the event listeners to finish processing before continuing execution. It's useful when you need to ensure that all side effects have been completed before proceeding.

{"const Emittery = require('emittery');\nconst emitter = new Emittery();\n\n(async () => {\n  await emitter.emit('event', 'some data');\n  console.log('Event emitted');\n})();"}

Namespaced events

This feature allows you to create and listen for namespaced events, which can help in organizing event types and avoiding name collisions.

{"const Emittery = require('emittery');\nconst emitter = new Emittery();\n\nemitter.on('namespace:event', () => {\n  console.log('Namespaced event fired');\n});\n\nemitter.emit('namespace:event');\n//=> 'Namespaced event fired'"}

Clearing listeners

This feature allows you to remove listeners from events, either all listeners from a specific event or all listeners from all events.

{"const Emittery = require('emittery');\nconst emitter = new Emittery();\n\nconst listener = () => {\n  console.log('Event fired');\n};\nemitter.on('event', listener);\n\nemitter.clearListeners('event');\nemitter.emit('event');\n// No output, because the listener was removed"}

Other packages similar to emittery

Keywords

FAQs

Package last updated on 17 Oct 2020

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc