the spectre
the spectre

Reputation: 350

Behavior of async package

What would the following code using the async package do:

action <- async $ mapM_ someFunc someList
wait action

Will this merely spawn a single thread in which mapM_ occurs? (Implying that this has no benefit over just mapM_ someFunc someList)

Or will it perform the mapM_ action asynchronously (or is mapConcurrently the only way to get such behavior)?

Upvotes: 0

Views: 35

Answers (1)

jberryman
jberryman

Reputation: 16645

Will this merely spawn a single thread in which mapM_ occurs?

Yes, it will fork a thread and immediately block waiting for the mapM_ to finish and return a () (or to throw an exception).

The async package is very simple; you might like to look at the source to see how it all works together and learn more about the underlying haskell concurrency primitives.

Upvotes: 1

Related Questions