-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Resolve undefined IO throwing behavior in the presence of async and non-termination #110
Comments
Apparently CompletableFuture.allOf(CompletableFuture.supplyAsync(() -> {
throw new IllegalStateException("kaboom");
}), CompletableFuture.supplyAsync(() -> {
LockSupport.park();
return null;
})).join(); // blocks forever, never throws |
That code should probably wait forever. |
There's certainly a good reason for it to wait forever (and that's currently what would happen), but there's no reason that the operational semantics couldn't be specified by the consumer either. For instance, I could certainly imagine a semantics for To do this properly would require being able to tap into the |
I see what you are saying. Would Execution Platform be an implementation detail? Regarding pulling IO out of the library I don’t know why would that be necessary. could it be the case that we could achieve both executions desired with two different IO classes? IO (IOWaitAll) Then, you can use a different execution strategy for that class, that allows cancelling all other tasks as soon as we throw on one of them. I could give it a try for a poc implementation |
Then the consumer would do: cancellAllOnThrow(throwImmediately.discardL(parkForever)).unsafePerformAsyncIO().join(); |
@jnape I watched this talk recently, talking about IO and analogous implementations in Scala and how the cats-effect library solves a lot of the previous issues with a bunch of IO classes: I am not sure it will completely solve the issue but it sounds really interesting: |
I just heard this talk that gives an intro into Lawvere theory A categorical view of computational effects - Emily Riehl |
Suppose we have the following
IO
tree:What should the result be? Should it throw, or block?
Intuitively, it feels like it should probably throw immediately, and why wouldn't it? Well, because there is asynchrony, and since
discardL
is just a sugaryzip
call, and sincezip
can only execute once both results have been computed, the backing future holding the thrown exception will never be interrogated, so the exception will never propagate.Investigate whether or not a principled approach to parallel
IO
can also easily immediately propagate exceptions under the context of asynchrony without violating correctness.The text was updated successfully, but these errors were encountered: