Skip to content

Commit

Permalink
process: runtime deprecate multipleResolves
Browse files Browse the repository at this point in the history
PR-URL: #41896
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
benjamingr committed Feb 13, 2022
1 parent ceaa299 commit 60b8e79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3075,12 +3075,15 @@ the errors used for value type validation.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/41896
description: Runtime deprecation.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/41872
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime.

This event was deprecated because it did not work with V8 promise combinators
which diminished its usefulness.
Expand Down
11 changes: 10 additions & 1 deletion lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {
setPromiseRejectCallback
} = internalBinding('task_queue');

const { deprecate } = require('internal/util');

const {
noSideEffectsToString,
triggerUncaughtException
Expand Down Expand Up @@ -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();
}
});
}

Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-warn-multipleResolves.mjs
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 60b8e79

Please sign in to comment.