
On Sat, Jul 5, 2014 at 3:58 AM, grant weyburne
Hi Cafe,
Is there any way to simplify this async code to somehow merge the withAsync code into the STM code? Looking at the code for tstABorCD it is not easy to see that it is really just (A&&B)||(C&&D). Here is the code:
Thanks for any pointers, Grant
The code as-is doesn't actually look too bad to me. But it *might* be a bit easier to read if instead of withAsync, waitSTM, and registerDelay, you used race, concurrently, and timeout. That might look something like this (untested): let toList (x, y) = [x, y] ab = toList <$> concurrently (doStuff 6) (doStuff 12) cd = toList <$> concurrently (doStuff 8) (doStuff 10) res <- timeout (1000000 * 20) $ race ab cd return $ maybe [] (either id id) res Michael