mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
Add `util.callbackify(function)` for creating callback style functions from functions returning a `Thenable` PR-URL: https://github.com/nodejs/node/pull/12712 Fixes: https://github.com/nodejs/CTC/issues/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>
23 lines
530 B
JavaScript
23 lines
530 B
JavaScript
'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));
|
|
}
|