| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,24 @@ wrapped function rejects a `Promise` with a falsy value as a reason, the value | |||
| 76 | 76 | is wrapped in an `Error` with the original value stored in a field named | |
| 77 | 77 | `reason`. | |
| 78 | 78 | ||
| 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 | + | ||
| 80 | 97 | function fn() { | |
| 81 | 98 | return Promise.reject(null); | |
| 82 | 99 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments