simonmar / async

Run IO operations asynchronously and wait for their results
BSD 3-Clause "New" or "Revised" License
323 stars 65 forks source link

Add ConcurrentlyE. #120

Closed danidiaz closed 3 years ago

danidiaz commented 3 years ago

I often find useful a generalized version of Concurrently that wraps a IO (Either e a) instead of a IO a, and for which the Applicative behaves like a mix of race and concurrently: if one of the actions returns a Left, cancel the other one and immediately return the Left. If both actions return a Right, behave similarly to Concurrently.

The alternative is to simply use Concurrently and throw and catch exceptions, but I've found that solution less ergonomic (when the "error" e is some interesting type, you have to declare a special-purpose exception in order to hold it).

A type similar to ConcurrentlyE is already provided by the conceit package.

simonmar commented 3 years ago

Seems reasonable, although I haven't run into a need for this myself.