Skip to content

Use onException in withAsyncUsing#185

Open
edsko wants to merge 1 commit into
simonmar:masterfrom
edsko:edsko/onException-in-withAsyncUsing
Open

Use onException in withAsyncUsing#185
edsko wants to merge 1 commit into
simonmar:masterfrom
edsko:edsko/onException-in-withAsyncUsing

Conversation

@edsko
Copy link
Copy Markdown
Contributor

@edsko edsko commented May 20, 2026

This is quite a central function in async; the pattern

.. `catch` \e ->
  ..
  throwIO e

should be avoided in GHC >= 9.12, as it will add unnecessary WhileHandling annotations. There are low level functions which can be used when necessary (catchNoPropagate, rethrowIO), but in this particular case onException captures the same pattern, and it has been modified in recent GHC to use these new primitives. The oldest version of GHC that async.cabal lists as supported is 7.0.4, even though it's not tested in CI. I verified that onException was already available back then.

This is quite a central function in `async`; the pattern

```hs
.. `catch` \e ->
  ..
  throwIO e
```

should be avoided in GHC >= 9.12, as it will add unnecessary `WhileHandling` annotations. There are low level functions which can be used when necessary (`catchNoPropagate`, `rethrowIO`), but in this particular case `onException` captures the same pattern, and _it_ has been [modified][1] in recent GHC to use these new primitives. The oldest version of GHC that `async.cabal` lists as supported is 7.0.4, even though it's not tested in CI. I verified that `onException` was already available [back then][2].

[1]: https://hackage.haskell.org/package/ghc-internal-9.1201.0/docs/src/GHC.Internal.Control.Exception.Base.html#onException
[2]: https://hackage.haskell.org/package/base-4.3.0.0/docs/src/Control-Exception-Base.html#onException
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

Successfully merging this pull request may close these issues.

1 participant