From 3b461870bef9223e06eceb8dfd790443100e0d64 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 1 Jun 2016 23:25:18 -0400 Subject: [PATCH] doc: Backport ee.once doc clarifications to 4.x. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/7103 Reviewed-By: Colin Ihrig Reviewed-By: Robert Lindstaedt Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Сковорода Никита Андреевич --- doc/api/events.markdown | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/api/events.markdown b/doc/api/events.markdown index 500d046f9e59f7..464a0f61570113 100644 --- a/doc/api/events.markdown +++ b/doc/api/events.markdown @@ -130,7 +130,7 @@ myEmitter.emit('event'); ``` Using the `eventEmitter.once()` method, it is possible to register a listener -that is immediately unregistered after it is called. +that is unregistered before it is called. ```js const myEmitter = new MyEmitter(); @@ -338,9 +338,8 @@ Returns a reference to the `EventEmitter` so calls can be chained. ### emitter.once(eventName, listener) -Adds a **one time** `listener` function for the event named `eventName`. This -listener is invoked only the next time `eventName` is triggered, after which -it is removed. +Adds a **one time** `listener` function for the event named `eventName`. The +next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => {