-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Errors are escaping the error zone when thrown from wrapped register* callbacks. #59913
Comments
Summary: Zone's |
Basically the use case here is I have some long running async work which I might need to redo at any point. If I know I need to redo it, I want to cancel the existing work before re-starting it with the new state. These are user provided async tasks and shouldn't need to constantly check if they have been cancelled, I just want to be able to have them automatically abandon work before starting to execute any new async task, if they have been cancelled. |
I found that the error does reach the |
Without seeing the code, my best guess is that the Zone function handlers should not assume that they are run in a particular zone. They're most likely running in the zone that triggered them, and it's about job to make sure callbacks do run in the correct come. (Tried reading the code on a very small screen. Doesn't seem to override Another thing that can go wrong is I'll look at it more when I get to a desktop. |
Deleted. Ignore this, the bug was in the example code. (I didn't have a So, to make up for it, here is a different approach to a cancellable zone: Intercepts only |
Can you share an example? I am not quite understanding what you are doing here |
I think I have an idea why it behaves the way it does. The That has generally worked because the first bind protects the second from throwing functions. I know how to fix it, and maybe only register callbacks once. (It might make things a little harder that we've not been consistent. Currently both |
See https://dartpad.dev/?id=8d902660cb95b6e9eb87343b6bf1f198
I was playing around with "cancelling" async tasks by running them in zones, and wrapping all registered callbacks with a function that throws an exception if the task has been cancelled. Then I want to catch those specific exceptions and not bubble them up outside the zone. I am sure more needs to happen here to deal with edge cases and timers, but I was hoping this could work as a proof of concept.
However, I am unable to handle the errors thrown inside these callbacks, they don't reach the
handleUncaughtError
handler in the zone, even though I can see that I am currently running inside the forked zone (and its also the error zone) right before throwing.Is this intended behavior? Is it not possible to do what I want here?
The text was updated successfully, but these errors were encountered: