worm-scraper/lib/track-rejections.js
2015-05-06 00:42:55 +02:00

17 lines
423 B
JavaScript

"use strict";
let currentId = 0;
const tracker = new WeakMap();
process.on("unhandledRejection", function (reason, promise) {
tracker.set(promise, ++currentId);
console.error(`Unhandled rejection (${currentId}): `);
console.error(reason.stack);
});
process.on("rejectionHandled", function (promise) {
const id = tracker.get(promise);
tracker.delete(promise);
console.error(`Rejection handled (${id})`);
});