Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nh2 opened this issue Dec 5, 2021 · 1 comment

Comments

@nh2
Copy link
Contributor

nh2 commented Dec 5, 2021

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.

@parsonsmatt
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants