Skip to content

Commit 3b46187

Browse files
lanceMyles Borins
authored and
Myles Borins
committed
doc: Backport ee.once doc clarifications to 4.x.
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 Ref: #6371 PR-URL: #7103 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 4067cde commit 3b46187

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

doc/api/events.markdown

+3-4
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();
@@ -338,9 +338,8 @@ Returns a reference to the `EventEmitter` so calls can be chained.
338338

339339
### emitter.once(eventName, listener)
340340

341-
Adds a **one time** `listener` function for the event named `eventName`. This
342-
listener is invoked only the next time `eventName` is triggered, after which
343-
it is removed.
341+
Adds a **one time** `listener` function for the event named `eventName`. The
342+
next time `eventName` is triggered, this listener is removed and then invoked.
344343

345344
```js
346345
server.once('connection', (stream) => {

0 commit comments

Comments
 (0)