Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vladfrangu/async_event_emitter

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vladfrangu/async_event_emitter

An event emitter implementation with async support in mind

  • 2.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
182K
decreased by-14.58%
Maintainers
1
Weekly downloads
 
Created

What is @vladfrangu/async_event_emitter?

@vladfrangu/async_event_emitter is an npm package that provides an asynchronous event emitter. It allows you to handle events in an asynchronous manner, making it suitable for scenarios where you need to perform asynchronous operations in response to events.

What are @vladfrangu/async_event_emitter's main functionalities?

Basic Event Emission

This feature allows you to emit events and handle them asynchronously. The event handler can perform asynchronous operations, such as fetching data from a database or an API.

const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');

const emitter = new AsyncEventEmitter();

emitter.on('event', async (data) => {
  console.log('Event received:', data);
});

(async () => {
  await emitter.emit('event', { key: 'value' });
})();

Handling Multiple Listeners

This feature allows you to register multiple listeners for the same event. All listeners will be called asynchronously when the event is emitted.

const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');

const emitter = new AsyncEventEmitter();

emitter.on('event', async (data) => {
  console.log('First listener:', data);
});

emitter.on('event', async (data) => {
  console.log('Second listener:', data);
});

(async () => {
  await emitter.emit('event', { key: 'value' });
})();

Removing Listeners

This feature allows you to remove specific listeners from an event. This is useful for cleaning up resources or stopping certain operations when they are no longer needed.

const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');

const emitter = new AsyncEventEmitter();

const listener = async (data) => {
  console.log('Event received:', data);
};

emitter.on('event', listener);

(async () => {
  await emitter.emit('event', { key: 'value' });
  emitter.off('event', listener);
  await emitter.emit('event', { key: 'value' }); // This will not trigger the listener
})();

Other packages similar to @vladfrangu/async_event_emitter

Keywords

FAQs

Package last updated on 03 Jul 2024

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