async icon indicating copy to clipboard operation
async copied to clipboard

docs: Document that `withAsync` does not propagate exceptions in the first argument

Open nh2 opened this issue 3 years ago • 1 comments

When I wrote PRs #104 and #105, I described withAsync as equally safe as race. That is wrong.

withAsync silently swallows exceptions in the first argument, e.g.

withAsync (error "TODO") $ \_ -> do -- more code

Here, the error will not bubble up.

(I haven't actually tried it with error yet, but with a worker thread doing a forever, and was surprised that it just didn't work, when in fact a No such file or directory was silently swallowed.)

race doesn't have this issue, in particular not the common pattern bResult <- fmap (either absurd id) $ race a b.

This should be made clearer in the docs in various places.

nh2 avatar Dec 05 '21 23:12 nh2

I also found this confusing.

The documentation does say that "If the operation throws an exception, then that exception is re-thrown by wait. This ensures property (1): No exception is swallowed."

If you want the exception thrown as an async, then you have to use link -

withAsync (error "TODO") $ \a -> do
  link a
  -- more code

will cause the exception in a to be asynchronously passed to the parent thread.

parsonsmatt avatar Nov 20 '22 23:11 parsonsmatt