-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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` Original-PR-URL: #12712 Fixes: nodejs/CTC#109 Original-Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Original-Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Original-Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Original-Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Original-Reviewed-By: Timothy Gu <timothygu99@gmail.com> Original-Reviewed-By: Anna Henningsen <anna@addaleax.net> PR-URL: #13750 Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
6 changed files
with
375 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.