From f9c362ff6c4fad4cf67df5a94ba5fdb9321a3d2b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 31 Aug 2020 19:36:20 -0700 Subject: [PATCH 1/2] doc: revise AbortSignal text and example using events.once() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a line to the example code to clarify what happens if an event is emitted after listening is canceled. Make minor revisions to surrounding text. PR-URL: https://github.com/nodejs/node/pull/35005 Reviewed-By: Michaël Zasso Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen --- doc/api/events.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/events.md b/doc/api/events.md index 387b9b15df1c39..92535b1fde4430 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -835,8 +835,7 @@ added: * `emitter` {EventEmitter} * `name` {string} * `options` {Object} - * `signal` {AbortSignal} An {AbortSignal} that may be used to cancel waiting - for the event. + * `signal` {AbortSignal} Can be used to cancel waiting for the event. * Returns: {Promise} Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given @@ -895,7 +894,7 @@ ee.emit('error', new Error('boom')); // Prints: ok boom ``` -An {AbortSignal} may be used to cancel waiting for the event early: +An {AbortSignal} can be used to cancel waiting for the event: ```js const { EventEmitter, once } = require('events'); @@ -918,6 +917,7 @@ async function foo(emitter, event, signal) { foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event +ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ### Awaiting multiple events emitted on `process.nextTick()` From cc754f2985c2c9afc9fdb185e15974644e459860 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 2 Sep 2020 20:55:43 -0700 Subject: [PATCH 2/2] doc: make AbortSignal text consistent in events.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Further minor modifications to AbortSignal text in events.md for consistency. PR-URL: https://github.com/nodejs/node/pull/35005 Reviewed-By: Michaël Zasso Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen --- doc/api/events.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/api/events.md b/doc/api/events.md index 92535b1fde4430..6c923308c782cf 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -1010,8 +1010,7 @@ added: * `emitter` {EventEmitter} * `eventName` {string|symbol} The name of the event being listened for * `options` {Object} - * `signal` {AbortSignal} An {AbortSignal} that can be used to cancel awaiting - events. + * `signal` {AbortSignal} Can be used to cancel awaiting events. * Returns: {AsyncIterator} that iterates `eventName` events emitted by the `emitter` ```js @@ -1041,7 +1040,7 @@ if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. -An {AbortSignal} may be used to cancel waiting on events: +An {AbortSignal} can be used to cancel waiting on events: ```js const { on, EventEmitter } = require('events');