<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 5, 2014 at 3:58 AM, grant weyburne <span dir="ltr"><<a href="mailto:gbwey9@gmail.com" target="_blank">gbwey9@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Cafe,<div><br></div><div>Is there any way to simplify this async code to somehow merge the withAsync code</div>

<div>into the STM code? Looking at the code for <span style="font-size:13px;color:rgb(46,101,156)">tstABorCD</span> it is not easy to see that<br>
</div><div>it is really just (A&&B)||(C&&D). Here is the code:</div><div> </div><div><a href="http://lpaste.net/106945" target="_blank">http://lpaste.net/106945</a><br></div><div><br></div><div>Thanks for any pointers,</div>


<div>Grant</div><div><br></div></div>
<br></blockquote><div><br></div><div>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):</div>

<div><br></div><div>let toList (x, y) = [x, y]</div><div>    ab = toList <$> concurrently (doStuff 6) (doStuff 12)</div><div>    cd = toList <$> concurrently (doStuff 8) (doStuff 10)</div><div>res <- timeout (1000000 * 20) $ race ab cd</div>

<div>return $ maybe [] (either id id) res</div><div><br></div><div>Michael</div></div></div></div>