Skip to content

onrejectionhandled / onunhandledrejection are missing in WorkerGlobalScope #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Nov 26, 2019 · 0 comments · Fixed by #804
Closed

onrejectionhandled / onunhandledrejection are missing in WorkerGlobalScope #807

ghost opened this issue Nov 26, 2019 · 0 comments · Fixed by #804

Comments

@ghost
Copy link

ghost commented Nov 26, 2019

This should work:

// In a worker

// Handle promise rejection...
self.onunhandledrejection((event: PromiseRejectionEvent) => {
  throw event.reason;
});

// ...so that let main thread know this promise is rejected.
Promise.new((resolve, reject) => {
  throw new Error('Oops!');
});

But I get Property 'onunhandledrejection' does not exist on type 'WorkerGlobalScope & typeof globalThis'..

The unhandledrejection event is useful for debugging when you write some code that imports modules asynchronously in a Worker.
I am not sure whether these events / handlers in WorkerGlobalScope context are defined by specifications, but at least MDN says "typically, this is the window, but may also be a Worker" and it works in a Worker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0 participants