Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quackamole-dev/quackamole-event-emitter
https://github.com/quackamole-dev/quackamole-event-emitter
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/quackamole-dev/quackamole-event-emitter
- Owner: quackamole-dev
- License: mit
- Created: 2021-05-08T21:02:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T02:30:28.000Z (almost 2 years ago)
- Last Synced: 2024-03-24T19:20:16.714Z (9 months ago)
- Language: TypeScript
- Size: 203 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Quackamole EventEmitter
=========================
[![npm version](https://badge.fury.io/js/quackamole-event-emitter.svg)](https://badge.fury.io/js/quackamole-event-emitter) [![GitHub license](https://img.shields.io/github/license/quackamole-dev/quackamole-event-emitter.svg)](https://github.com/quackamole-dev/quackamole-event-emitter/blob/main/LICENSE) ![Dependencies](https://img.shields.io/david/quackamole-dev/quackamole-event-emitter) [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/quackamole-dev/quackamole-event-emitter) ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/andreas-schoch/63f6547acd916bfb217f065a6357f29a/raw/quackamole-event-emitter__heads_github-actions-experimenting.json)## Install
```bash
npm install quackamole-event-emitter
```or
```bash
yarn add quackamole-event-emitter
```## Basic Usage
```typescript
import EventEmitter from 'quackamole-event-emitter';const emitter = new EventEmitter();
// basic
emitter.on('some-event', (evt: IEvent) => console.log(evt.data.foo), {once: true});
emitter.off('some-event', (evt: IEvent) => console.log(evt.data.foo), {once: true});
emitter.emit('some-event', {foo: 'bar'})
```## Experimental Usage
Subject to change over time depending on usefulness and usability.
### Wait for follow-up event
As a response to "ping" we expect the follow up event "pong" to be emitted.
```typescript
import EventEmitter from 'quackamole-event-emitter';const emitter = new EventEmitter();
emitter.on('ping', (evt: IEvent) => {
setTimeout(() => emitter.emit('pong', evt.data + ' world'), 1000);
});emitter.emit('ping', 'hello');
const pingPong: string = await emitter.onAsync('pong', (evt: IEvent) => {
evt.asyncHandle?.resolve(evt.data);
}); // pingPong === 'hello world';
```## License
MIT