mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
doc: use mjs/cjs blocks for callbackify null reason example
PR-URL: https://github.com/nodejs/node/pull/62884 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
4a32c00fb8
commit
74c6f85042
1 file changed
+18
-1
+18
-1
@@ -76,7 +76,24 @@ wrapped function rejects a `Promise` with a falsy value as a reason, the value
|
||||
is wrapped in an `Error` with the original value stored in a field named
|
||||
`reason`.
|
||||
|
||||
```js
|
||||
```mjs
|
||||
import util from 'node:util';
|
||||
|
||||
function fn() {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
const callbackFunction = util.callbackify(fn);
|
||||
|
||||
callbackFunction((err, ret) => {
|
||||
// When the Promise was rejected with `null` it is wrapped with an Error and
|
||||
// the original value is stored in `reason`.
|
||||
err && Object.hasOwn(err, 'reason') && err.reason === null; // true
|
||||
});
|
||||
```
|
||||
|
||||
```cjs
|
||||
const util = require('node:util');
|
||||
|
||||
function fn() {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user