Skip to content

Commit

Permalink
feat: use a global symbol for util.promisify.custom
Browse files Browse the repository at this point in the history
Define `util.promisify.custom`
as `Symbol.for("nodejs.util.inspect.custom")`, rather than
as `Symbol("util.inspect.custom")`.

This allows custom `promisify` wrappers to easily/safely be defined
in non‑Node.js environments.

Refs: nodejs/node#31647
Refs: nodejs/node#31672
  • Loading branch information
ExE-Boss committed Feb 8, 2020
1 parent 3c89541 commit f89af7d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
var kCustomPromisifiedSymbol =
typeof Symbol === 'function' && typeof Symbol['for'] === 'function'
? Symbol['for']('nodejs.util.promisify.custom')
: undefined;

exports.promisify = function promisify(original) {
if (typeof original !== 'function')
Expand Down

0 comments on commit f89af7d

Please sign in to comment.