Skip to content

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

Open

Description

@nh2

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.

Activity

  1. parsonsmatt commented on Nov 20, 2022

    @parsonsmatt
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions