-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix cancel
in exception handling code
#96
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
module UnliftIO.ExceptionSpec (spec) where | ||
|
||
import qualified Control.Exception | ||
import Control.Monad (void, (<=<)) | ||
import Control.Monad (void, (<=<), when) | ||
import Data.Bifunctor (first) | ||
import Test.Hspec | ||
import UnliftIO | ||
|
@@ -79,6 +79,27 @@ spec = do | |
result <- withWrappedAsyncExceptionThrown $ \m -> trySyncOrAsync (void m) | ||
first fromExceptionUnwrap result `shouldBe` Left (Just Exception1) | ||
|
||
describe "withException" $ do | ||
it "should work when withAsync is in the handler" $ do | ||
let | ||
action = | ||
error "oops" | ||
`onException` do | ||
let | ||
timerAction n = do | ||
threadDelay 1000000 | ||
when (n < 10) $ do | ||
timerAction (n + 1) | ||
withAsync (timerAction 0) $ \a -> do | ||
cancel a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be replaced with |
||
eresult <- | ||
race | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
(action `shouldThrow` errorCall "oops") | ||
(do | ||
threadDelay 1000000 | ||
pure 10) | ||
eresult `shouldBe` Left () | ||
|
||
describe "fromExceptionUnwrap" $ do | ||
it "should be the inverse of toAsyncException" $ do | ||
fromExceptionUnwrap (toAsyncException Exception1) `shouldBe` Just Exception1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this line fixes the test. But it also removes the guarantee that
action `onException` cleanup
will definitely completecleanup
.