https://github.com/131/eventemitter-async
https://github.com/131/eventemitter-async
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/131/eventemitter-async
- Owner: 131
- License: mit
- Created: 2017-09-20T21:37:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-04T00:03:41.000Z (about 2 years ago)
- Last Synced: 2025-06-01T07:11:41.729Z (about 1 year ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
eventemitter with async/await. [eventemitter-async](https://github.com/131/eventemitter-async) mimics `require('events').EventEmitter` API.
[](https://travis-ci.org/131/eventemitter-async)
[](https://coveralls.io/github/131/eventemitter-async?branch=master)
[](https://www.npmjs.com/package/eventemitter-async)
[](http://opensource.org/licenses/MIT)
# API
```
var sleep = require('nyks/async/sleep');
var Event = require('eventemitter-async');
var event = new Event();
var cafe = {color:'black'};
event.on("start", async function() {
await sleep(1);
console.log("Hi, coffee is ", this.color);
}, cafe);
event.emit("start");
```
# Errors (&promises)
event.emit() will return a promise you can work with if you need [to handle errors](https://github.com/131/eventemitter-async/blob/master/test/errors.js)
# Notes
You can set an optional 3rd parameter and set the context ("this") in event registration.
# Credits
* [131](https://github.com/131)
# Keywords / shout box
events, eventemitter2, uclass, promise, binding