question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to conCollect but stop on first exception?

See original GitHub issue

Consider 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:open
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cmeerencommented, Feb 7, 2022

Thank you, that is very helpful. I will look carefully at your code and explanations when time permits.

0reactions
charlieturndorfcommented, Jan 31, 2022

It also occurred to me that you could use latches instead of alts, which might lead to a more elegant design.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found