Skip to content

Commit 36207c6

Browse files
lanceFishrock123
authored andcommitted
doc: correctly document the behavior of ee.once().
Addresses #5566. The `ee.once()` function is currently documented as invoking the listener, and then removing it when the event is triggered. However, this is not really the case. The listener is removed and _then_ invoked. This only matters in a narrow set of use cases, but when it matters, it matters that the docs are correct. See the issue (#5566) for a discussion on why the code has not been modified to match the documentation, but instead the documentation has been modified to match the code. Fixes: #5566 PR-URL: #6371 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Lindstaedt <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
1 parent 19fb134 commit 36207c6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

doc/api/events.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ myEmitter.emit('event');
130130
```
131131

132132
Using the `eventEmitter.once()` method, it is possible to register a listener
133-
that is immediately unregistered after it is called.
133+
that is unregistered before it is called.
134134

135135
```js
136136
const myEmitter = new MyEmitter();
@@ -376,9 +376,8 @@ myEE.emit('foo');
376376
* `eventName` {string|Symbol} The name of the event.
377377
* `listener` {Function} The callback function
378378

379-
Adds a **one time** `listener` function for the event named `eventName`. This
380-
listener is invoked only the next time `eventName` is triggered, after which
381-
it is removed.
379+
Adds a **one time** `listener` function for the event named `eventName`. The
380+
next time `eventName` is triggered, this listener is removed and then invoked.
382381

383382
```js
384383
server.once('connection', (stream) => {
@@ -427,8 +426,8 @@ Returns a reference to the `EventEmitter` so calls can be chained.
427426
* `listener` {Function} The callback function
428427

429428
Adds a **one time** `listener` function for the event named `eventName` to the
430-
*beginning* of the listeners array. This listener is invoked only the next time
431-
`eventName` is triggered, after which it is removed.
429+
*beginning* of the listeners array. The next time `eventName` is triggered, this
430+
listener is removed, and then invoked.
432431

433432
```js
434433
server.prependOnceListener('connection', (stream) => {

0 commit comments

Comments
 (0)