summaryrefslogtreecommitdiff
path: root/doc/api/util.md
diff options
context:
space:
mode:
authorExE Boss <3889017+ExE-Boss@users.noreply.github.com>2020-02-07 11:40:00 +0100
committerAnna Henningsen <anna@addaleax.net>2020-03-12 19:51:25 +0100
commitba684805b6c0eded76e5cd89ee00328ac7a59365 (patch)
treeb447896ae6f5f4cdc549e0344ee2a1c0c9b03856 /doc/api/util.md
parent7f44d2ced6dc19264778fe749e87de33e02926f1 (diff)
downloadnode-new-ba684805b6c0eded76e5cd89ee00328ac7a59365.tar.gz
util: use a global symbol for `util.promisify.custom`
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. Fixes: https://github.com/nodejs/node/issues/31647 PR-URL: https://github.com/nodejs/node/pull/31672 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r--doc/api/util.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index 151e476993..2c0062eff7 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -995,11 +995,32 @@ throw an error.
### `util.promisify.custom`
<!-- YAML
added: v8.0.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/31672
+ description: This is now defined as a shared symbol.
-->
* {symbol} that can be used to declare custom promisified variants of functions,
see [Custom promisified functions][].
+In addition to being accessible through `util.promisify.custom`, this
+symbol is [registered globally][global symbol registry] and can be
+accessed in any environment as `Symbol.for('nodejs.util.promisify.custom')`.
+
+For example, with a function that takes in
+`(foo, onSuccessCallback, onErrorCallback)`:
+
+```js
+const kCustomPromisifiedSymbol = Symbol.for('nodejs.util.promisify.custom');
+
+doSomething[kCustomPromisifiedSymbol] = (foo) => {
+ return new Promise((resolve, reject) => {
+ doSomething(foo, resolve, reject);
+ });
+};
+```
+
## Class: `util.TextDecoder`
<!-- YAML
added: v8.3.0