async-pool icon indicating copy to clipboard operation
async-pool copied to clipboard

Document example usage of `mapReduce` (and any similar functions).

Open vdukhovni opened this issue 6 years ago • 1 comments

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).

vdukhovni avatar Nov 17 '19 00:11 vdukhovni

Excellent idea.

jwiegley avatar Nov 20 '19 21:11 jwiegley