From 60b8e795993cd6fcb7dc70d696a6ebe7aa0ef3d4 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Tue, 8 Feb 2022 18:28:25 +0200 Subject: [PATCH] process: runtime deprecate multipleResolves PR-URL: https://github.com/nodejs/node/pull/41896 Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- doc/api/deprecations.md | 5 ++++- lib/internal/process/promises.js | 11 ++++++++++- test/parallel/test-warn-multipleResolves.mjs | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-warn-multipleResolves.mjs diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index adffb43c52825d..98a46828e98c1b 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3075,12 +3075,15 @@ the errors used for value type validation. -Type: Documentation-only +Type: Runtime. This event was deprecated because it did not work with V8 promise combinators which diminished its usefulness. diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index fd5cb73fbbe4bb..36b4bb760ef9c2 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -20,6 +20,8 @@ const { setPromiseRejectCallback } = internalBinding('task_queue'); +const { deprecate } = require('internal/util'); + const { noSideEffectsToString, triggerUncaughtException @@ -124,11 +126,18 @@ function promiseRejectHandler(type, promise, reason) { } } +const multipleResolvesDeprecate = deprecate( + () => {}, + 'The multipleResolves event has been deprecated.', + 'DEPXXXX' +); function resolveError(type, promise, reason) { // We have to wrap this in a next tick. Otherwise the error could be caught by // the executed promise. process.nextTick(() => { - process.emit('multipleResolves', type, promise, reason); + if (process.emit('multipleResolves', type, promise, reason)) { + multipleResolvesDeprecate(); + } }); } diff --git a/test/parallel/test-warn-multipleResolves.mjs b/test/parallel/test-warn-multipleResolves.mjs new file mode 100644 index 00000000000000..f6fb0affbd3dc6 --- /dev/null +++ b/test/parallel/test-warn-multipleResolves.mjs @@ -0,0 +1,14 @@ +import { expectWarning, mustCall } from '../common/index.mjs'; + +expectWarning( + 'DeprecationWarning', + 'The multipleResolves event has been deprecated.', + 'DEPXXXX', +); + +process.on('multipleResolves', mustCall()); + +new Promise((resolve) => { + resolve(); + resolve(); +});