promise-worker-bi
promise-worker-bi copied to clipboard
Add an event listener for unhandledrejections?
Hi,
Thanks for the library.
I can see there is an event listener to catch global "error" events, but not on global "unhandledrejection" events.
E.g if my worker code does something like below, it won't get handled by the registerError callback.
const test = function() {
return new Promise(function(resolve, reject) {
setTimeout(() => {
reject(new Error("test error"))
}, 5000);
})
}
test();
Would it make sense to add a global listener for that, e.g. could just "re-throw" that error
self.addEventListener("unhandledrejection", function (e) {
e.preventDefault();
throw e.reason;
});
Yeah, it probably does make sense to handle "unhandledrejection" events similar to "error" events. I'm not sure when I'll get around to adding it, but probably eventually. Or, PR welcome :)
I wonder if there are any other events that should be handled similarly too..