How to conCollect but stop on first exception?
See original GitHub issueConsider the following:
Job.conCollect [
job {
printfn "start 1"
do! timeOutMillis 1000
printfn "end 1"
}
job {
printfn "start 2"
do! timeOutMillis 2000
printfn "end 2"
}
job {
printfn "start 3"
failwith "foo"
}
When run, this prints all the “start x” messages, waits for one second, prints “end 1”, waits another second, prints “end 2”, and then immediately throws.
I would like to run jobs in parallel (and get their results), but stop on the first exception, because (in my use-case) if one of the jobs throws an exception, the whole request fails and it makes no sense to wait for anything else, or to return more than the first exception.
Is there a simple way to do this in Hopac?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Throw java exception and stops
What you can do is handle the exception in the main method, which calls the other method. Create multiple catch for different Exceptions...
Read more >Exception propagation: When should I catch exceptions?
The statement or consensus around exception handling is to throw when execution cannot continue due to just that - an exception. I get...
Read more >Issues · Hopac/Hopac
Example of paranoid function? ... How to conCollect but stop on first exception? ... How can uncaught exception errors be redirected? ... How...
Read more >Answers to Questions and Exercises - Exceptions
Answer: This first handler catches exceptions of type Exception ; therefore, it catches any exception, including ArithmeticException .
Read more >Basic try-catch-finally Exception Handling in Java
This tutorial explains how the basic try-catch-finally exception handling mechanisms work in Java.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you, that is very helpful. I will look carefully at your code and explanations when time permits.
It also occurred to me that you could use latches instead of alts, which might lead to a more elegant design.