-
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
Bridging Dart Exceptions with Isolates: Addressing the Incompatibility #59608
Comments
Summary: Dart isolates don't directly support exception propagation, requiring manual conversion to values. This adds complexity when bridging isolates and exception-based error handling. |
Isolates rely on sending objects (errors are objects too) to communicate anything between different isolates. What do you suggest to do? The current It's definitely possible to run a computation that returns a Which operations, or primitives, are you missing? |
@lrhn I have limited knowledge of Isolate so I might be doing something wrong. I have a function List<Future> futures;
for (var message in messages) {
var future = compute(Fibonacci, message);
futures.add(future);
}
try {
results = Future.wait(futures)
} catch (e) {
print("I lost everything if one fail!")
} from my understanding if one of the Fibonacci calls throw I lose everything My really ugly solution is wrapping Fibonacci into: (int result, String error) FibonachiWithoutException(int message) {
try {
return Fibonachi(message), null
} catch(e) {
return 0, e.toString();
}
} so I have a list of results and I can check if it's an error or a value (really golang style) removing the need for |
This doesn't seem to be about isolates, just how to combine multiple synchronous results. You have a number of futures, where some may contain errors, and you want to combine those into a single result, somehow, that represents all of the results. If you change Then you have all the results, and can decide how you want to continue with those. A more direct and Dart-like version of the Go-style would be to use the |
@lrhn thanks for your great answer!
Because of this, I came up with this solution, but it's more about, "How to compute multiple values in parallel using Dart Isolate?" I don't care about having all the results all at once, I would much prefer to get their results as soon as they are finished (with some clue of which message has been sent to them preferably) so I can show a progress indication for example or move to the next steps for those fast to compute values. Do you see any more relevant way to compute multiple values in parallel? |
When exploring the Dart standard library, it becomes evident that exceptions are the primary mechanism for handling errors. This approach works seamlessly in most scenarios—until you introduce isolates into the equation. Isolates rely on values to handle errors, creating a dissonance between the two paradigms.
This mismatch forces developers to write wrapper functions to convert exceptions into value-based errors to make them compatible with isolates. This process can be tedious and introduces unnecessary complexity, especially when working with existing Dart codebases.
A potential improvement would be enabling isolates to propagate exceptions back to the sender. This enhancement could significantly reduce the friction caused by this inconsistency, allowing for a more harmonious interaction between isolates and Dart's standard error-handling mechanisms.
Currently, this disconnect makes it cumbersome to leverage isolates effectively within Dart, particularly in projects that depend on exception-driven error handling.
The text was updated successfully, but these errors were encountered: