Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alvarobernalg/ts-promisify-event-emitter
Another implementation of Event Emitter but strongly typed, "promisified" and with configurable max listeners
https://github.com/alvarobernalg/ts-promisify-event-emitter
deno emitter event listener node promise
Last synced: about 1 month ago
JSON representation
Another implementation of Event Emitter but strongly typed, "promisified" and with configurable max listeners
- Host: GitHub
- URL: https://github.com/alvarobernalg/ts-promisify-event-emitter
- Owner: AlvaroBernalG
- License: mit
- Created: 2019-07-20T15:31:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-15T15:27:55.000Z (about 4 years ago)
- Last Synced: 2024-11-24T19:20:25.443Z (about 1 month ago)
- Topics: deno, emitter, event, listener, node, promise
- Language: TypeScript
- Homepage: https://alvarobg.com/deno/ts_promisify_event_emitter/1.1.10/index.ts
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-promisify-event-emitter
> Another implementation of [Event Emitter](https://nodejs.org/api/events.html) but with Promises[![travis](https://travis-ci.org/AlvaroBernalG/ts-promisify-event-emitter.svg?branch=master)](https://travis-ci.org/AlvaroBernalG/ts-promisify-event-emitter.svg?branch=master) [![npm version](https://badge.fury.io/js/ts-promisify-event-emitter.svg)](https://badge.fury.io/js/ts-promisify-event-emitter)
## Install
```
$ npm install ts-promisify-event-emitter
```## Usage
Basic usage:
```ts
import EventEmitterPromisified, {Message, Callback} from 'ts-promisify-event-emitter';// Result type
interface IUser {
name: string;
lastname: string;
}
// Query type
interface IQuery {
id: string;
}async function getUserFromDatabase(id: string): Promise {
// do something async
return {
name: 'Test',
lastname: 'Testing'
}
}const events = new EventEmitterPromisified();
const callback: Callback = async (message: Message): Promise => {
const user: IUser = await getUserFromDatabase(message.payload.id);
return user;
}events.on('getUser', callback);
(async function start() {
const query: Message = {payload: {id: "ID-1234"}};
const [user] = await events.emit('getUser', query);
console.log(`The user is: Name=${user.name}, lastname=${user.lastname}.`);
})();
```### Deno
```ts
import EventEmitterPromisified, {Message, Callback} from 'https://alvarobg.com/deno/ts_promisify_event_emitter/1.1.10/index.ts';```
## ContributingAll contributions are welcome.
## License
MIT