You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
485 B
JavaScript
18 lines
485 B
JavaScript
"use strict";
|
|
|
|
const capturePromise = require("./");
|
|
|
|
function dubiousUserSuppliedCallback() {
|
|
if (Math.random() < 0.5) {
|
|
return Promise.resolve(true);
|
|
} else {
|
|
throw new Error(`Oops, this is synchronously thrown!`);
|
|
}
|
|
}
|
|
|
|
(async function () {
|
|
let promise = capturePromise(() => dubiousUserSuppliedCallback());
|
|
console.log(promise); // Always prints a Promise, regardless of whether the callback throws or not
|
|
await promise; // ... and we can await it like any Promise!
|
|
})();
|