async-pool
async-pool copied to clipboard
Document example usage of `mapReduce` (and any similar functions).
It was not immediately obvious to me how to construct a correct invocation of mapReduce. Its signature shows it returning an STM (Async a), so it seemed not too far-fetched to try to wait for it in the same STM transaction that created it:
withTaskGroup 8 \tg -> atomically (mapReduce tg tasklist >>= waitSTM)
but that fails with the dreaded "thread blocked indefinitely" error. It turns out (after finding an example in one of the tests) that the correct invocation is rather:
withTaskGroup 8 \tg -> atomically (mapReduce tg tasklist) >>= wait
With the waitSTM (via wait) in a separate atomic transaction. Some text showing correct usage may also be helpful to others, perhaps with an explanation motivating the need for the separation (but a simple dictate may suffice).
Excellent idea.