@@ -146,22 +146,26 @@ withTransactionMode mode conn act =
146 commit conn
146 commit conn
149+-- | 'withTransactionModeRetry'' but with the exception type pinned to 'SqlError'.
150+withTransactionModeRetry :: forall a. TransactionMode -> (SqlError -> Bool) -> Connection -> IO a -> IO a
151+withTransactionModeRetry = withTransactionModeRetry'
149-- | Like 'withTransactionMode', but also takes a custom callback to
153-- | Like 'withTransactionMode', but also takes a custom callback to
150−-- determine if a transaction should be retried if an 'SqlError' occurs.
154+-- determine if a transaction should be retried if an exception occurs.
151−-- If the callback returns True, then the transaction will be retried.
155+-- If the callback returns 'True', then the transaction will be retried.
152−-- If the callback returns False, or an exception other than an 'SqlError'
156+-- If the callback returns 'False', or an exception other than an @e@
153-- occurs then the transaction will be rolled back and the exception rethrown.
157-- occurs then the transaction will be rolled back and the exception rethrown.
155-- This is used to implement 'withTransactionSerializable'.
159-- This is used to implement 'withTransactionSerializable'.
156−withTransactionModeRetry :: TransactionMode -> (SqlError -> Bool) -> Connection -> IO a -> IO a
160+withTransactionModeRetry' :: forall a e. E.Exception e => TransactionMode -> (e -> Bool) -> Connection -> IO a -> IO a
157−withTransactionModeRetry mode shouldRetry conn act =
161+withTransactionModeRetry' mode shouldRetry conn act =
158 mask $ \restore ->
162 mask $ \restore ->
159 retryLoop $ E.try $ do
163 retryLoop $ E.try $ do
160 a <- restore act `E.onException` rollback_ conn
164 a <- restore act `E.onException` rollback_ conn
161 commit conn
165 commit conn
164− retryLoop :: IO (Either SqlError a) -> IO a
168+ retryLoop :: IO (Either e a) -> IO a
165 retryLoop act' = do
169 retryLoop act' = do
166 beginMode mode conn
170 beginMode mode conn
167 r <- act'
171 r <- act'