Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c92cb6f

Browse filesBrowse files
watildeaduh95
authored andcommitted
doc: use mjs/cjs blocks for callbackify null reason example
PR-URL: #62884 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent d29fbc0 commit c92cb6f
Copy full SHA for c92cb6f

1 file changed

+18-1Lines changed: 18 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/util.md‎

Copy file name to clipboardExpand all lines: doc/api/util.md
+18-1Lines changed: 18 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,24 @@ wrapped function rejects a `Promise` with a falsy value as a reason, the value
7676
is wrapped in an `Error` with the original value stored in a field named
7777
`reason`.
7878

79-
```js
79+
```mjs
80+
import util from 'node:util';
81+
82+
function fn() {
83+
return Promise.reject(null);
84+
}
85+
const callbackFunction = util.callbackify(fn);
86+
87+
callbackFunction((err, ret) => {
88+
// When the Promise was rejected with `null` it is wrapped with an Error and
89+
// the original value is stored in `reason`.
90+
err && Object.hasOwn(err, 'reason') && err.reason === null; // true
91+
});
92+
```
93+
94+
```cjs
95+
const util = require('node:util');
96+
8097
function fn() {
8198
return Promise.reject(null);
8299
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.