From bb5a924dd7c336778f2d743ceb69e018358b83ad Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 14 Jun 2025 14:49:17 -0700 Subject: [PATCH] process: move multipleResolves event to EOL The `multipleResolves` event has been deprecated for several years now. It's time. --- doc/api/deprecations.md | 9 +- doc/api/process.md | 90 ------------------- lib/internal/process/promises.js | 70 +-------------- test/parallel/test-events-once.js | 1 - test/parallel/test-promise-swallowed-event.js | 58 ------------ .../test-timers-immediate-promisified.js | 2 - .../test-timers-interval-promisified.js | 2 - .../test-timers-timeout-promisified.js | 2 - test/parallel/test-warn-multipleResolves.mjs | 14 --- 9 files changed, 10 insertions(+), 238 deletions(-) delete mode 100644 test/parallel/test-promise-swallowed-event.js delete mode 100644 test/parallel/test-warn-multipleResolves.mjs diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 84f5224de2060c..119c2bc676f122 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3332,6 +3332,9 @@ the errors used for value type validation. -Type: Runtime +Type: End-of-Life -This event was deprecated because it did not work with V8 promise combinators -which diminished its usefulness. +This event was deprecated and removed because it did not work with V8 promise +combinators which diminished its usefulness. ### DEP0161: `process._getActiveRequests()` and `process._getActiveHandles()` diff --git a/doc/api/process.md b/doc/api/process.md index b3c74c99ec49b4..9182d25219c92f 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -176,95 +176,6 @@ process, the `message` argument can contain data that JSON is not able to represent. See [Advanced serialization for `child_process`][] for more details. -### Event: `'multipleResolves'` - - - -> Stability: 0 - Deprecated - -* `type` {string} The resolution type. One of `'resolve'` or `'reject'`. -* `promise` {Promise} The promise that resolved or rejected more than once. -* `value` {any} The value with which the promise was either resolved or - rejected after the original resolve. - -The `'multipleResolves'` event is emitted whenever a `Promise` has been either: - -* Resolved more than once. -* Rejected more than once. -* Rejected after resolve. -* Resolved after reject. - -This is useful for tracking potential errors in an application while using the -`Promise` constructor, as multiple resolutions are silently swallowed. However, -the occurrence of this event does not necessarily indicate an error. For -example, [`Promise.race()`][] can trigger a `'multipleResolves'` event. - -Because of the unreliability of the event in cases like the -[`Promise.race()`][] example above it has been deprecated. - -```mjs -import process from 'node:process'; - -process.on('multipleResolves', (type, promise, reason) => { - console.error(type, promise, reason); - setImmediate(() => process.exit(1)); -}); - -async function main() { - try { - return await new Promise((resolve, reject) => { - resolve('First call'); - resolve('Swallowed resolve'); - reject(new Error('Swallowed reject')); - }); - } catch { - throw new Error('Failed'); - } -} - -main().then(console.log); -// resolve: Promise { 'First call' } 'Swallowed resolve' -// reject: Promise { 'First call' } Error: Swallowed reject -// at Promise (*) -// at new Promise () -// at main (*) -// First call -``` - -```cjs -const process = require('node:process'); - -process.on('multipleResolves', (type, promise, reason) => { - console.error(type, promise, reason); - setImmediate(() => process.exit(1)); -}); - -async function main() { - try { - return await new Promise((resolve, reject) => { - resolve('First call'); - resolve('Swallowed resolve'); - reject(new Error('Swallowed reject')); - }); - } catch { - throw new Error('Failed'); - } -} - -main().then(console.log); -// resolve: Promise { 'First call' } 'Swallowed resolve' -// reject: Promise { 'First call' } Error: Swallowed reject -// at Promise (*) -// at new Promise () -// at main (*) -// First call -``` - ### Event: `'rejectionHandled'`