- Support EventTarget emitters in `events.once` from Node.js 12.11.0.
Now you can use the `events.once` function with objects that implement the EventTarget interface. This interface is used widely in
the DOM and other web APIs.
```js
var events = require('events');
var assert = require('assert');
async function connect() {
var ws = new WebSocket('wss://example.com');
await events.once(ws, 'open');
assert(ws.readyState === WebSocket.OPEN);
}
async function onClick() {
await events.once(document.body, 'click');
alert('you clicked the page!');
}
```
# 3.2.0
- Add `events.once` from Node.js 11.13.0.
To use this function, Promises must be supported in the environment. Use a polyfill like `es6-promise` if you support older browsers.
# 3.1.0 (2020-01-08)
`events` now matches the Node.js 11.12.0 API.
- pass through return value in wrapped `emitter.once()` listeners
Now, this works:
```js
emitter.once('myevent', function () { return 1; });
var listener = emitter.rawListeners('myevent')[0]
assert(listener() === 1);
```
Previously, `listener()` would return undefined regardless of the implementation.
Ported from https://github.com/nodejs/node/commit/acc506c2d2771dab8d7bba6d3452bc5180dff7cf
- Reduce code duplication in listener type check ([#67](https://github.com/Gozala/events/pull/67) by [@friederbluemle](https://github.com/friederbluemle)).
- Improve `emitter.once()` performance in some engines