forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `util.callbackify(function)` for creating callback style functions from functions returning a `Thenable` PR-URL: nodejs#12712 Fixes: nodejs/CTC#109 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
6 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// Used to test that `uncaughtException` is emitted | ||
|
||
const { callbackify } = require('util'); | ||
|
||
{ | ||
async function fn() { } | ||
|
||
const cbFn = callbackify(fn); | ||
|
||
cbFn((err, ret) => { | ||
throw new Error(__filename); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
// Used to test the `uncaughtException` err object | ||
|
||
const assert = require('assert'); | ||
const { callbackify } = require('util'); | ||
|
||
{ | ||
const sentinel = new Error(__filename); | ||
process.once('uncaughtException', (err) => { | ||
assert.strictEqual(err, sentinel); | ||
// Calling test will use `stdout` to assert value of `err.message` | ||
console.log(err.message); | ||
}); | ||
|
||
async function fn() { | ||
return await Promise.reject(sentinel); | ||
} | ||
|
||
const cbFn = callbackify(fn); | ||
cbFn((err, ret) => assert.ifError(err)); | ||
} |
Oops, something went wrong.