Skip to content

Commit 961bd4d

Browse files
committed
Handle the case for waitSTM
1 parent 37c49e4 commit 961bd4d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Control/Concurrent/Async/Internal.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ withAsyncUsing doFork = \action inner -> do
189189

190190

191191
-- | This function attempts at rethrowing while keeping the context
192-
-- This is internal and only working with GHC >=9.12
192+
-- This is internal and only working with GHC >=9.12, otherwise it fallsback to
193+
-- standard 'throwIO'
193194
rethrowIO' :: SomeException -> IO a
194195
#if MIN_VERSION_base(4,21,0)
195196
rethrowIO' e =
@@ -242,7 +243,20 @@ poll = atomically . pollSTM
242243
waitSTM :: Async a -> STM a
243244
waitSTM a = do
244245
r <- waitCatchSTM a
245-
either throwSTM return r
246+
either (rethrowSTM) return r
247+
248+
-- | This function attempts at rethrowing while keeping the context
249+
-- This is internal and only working with GHC >=9.12, otherwise it fallsback to
250+
-- standard 'throwSTM'
251+
rethrowSTM :: SomeException -> STM a
252+
#if MIN_VERSION_base(4,21,0)
253+
rethrowSTM e =
254+
case fromException e of
255+
Just (e' :: ExceptionWithContext SomeException) -> throwSTM (NoBacktrace e')
256+
Nothing -> throwSTM e
257+
#else
258+
rethrowSTM = throwSTM
259+
#endif
246260

247261
-- | A version of 'waitCatch' that can be used inside an STM transaction.
248262
--

0 commit comments

Comments
 (0)