Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36207c6

Browse filesBrowse 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 <cjihrig@gmail.com> Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
1 parent 19fb134 commit 36207c6
Copy full SHA for 36207c6

File tree

Expand file treeCollapse file tree

1 file changed

+5
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-6
lines changed
Open diff view settings
Collapse file

‎doc/api/events.md‎

Copy file name to clipboardExpand all lines: doc/api/events.md
+5-6Lines changed: 5 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.