Skip to content

Commit

Permalink
Exceptions 0.10.0 (#61)
Browse files Browse the repository at this point in the history
* implement generalBracket

* implement uninterruptibleMask

the previous implementation was just delegating to 'mask', and was thus
interruptible

* exceptions >= 0.10.0
  • Loading branch information
gelisam authored May 4, 2018
1 parent 492199d commit 199d924
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hint.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test-suite unit-tests
directory,
filepath,
extensible-exceptions,
exceptions == 0.8.*
exceptions >= 0.10.0

if !os(windows) {
build-depends: unix >= 2.2.0.0
Expand All @@ -56,7 +56,7 @@ library
ghc-boot,
mtl,
filepath,
exceptions == 0.8.*,
exceptions == 0.10.*,
random,
directory

Expand Down
15 changes: 14 additions & 1 deletion src/Control/Monad/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,20 @@ instance (MonadIO m, MonadMask m) => MonadMask (GhcT m) where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)

uninterruptibleMask = mask
uninterruptibleMask f = wrap $ \s ->
uninterruptibleMask $ \io_restore ->
unwrap (f $ \m -> (wrap $ \s' -> io_restore (unwrap m s'))) s
where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)

generalBracket acquire release body
= wrap $ \s -> generalBracket (unwrap acquire s)
(\a exitCase -> unwrap (release a exitCase) s)
(\a -> unwrap (body a) s)
where
wrap g = GhcT $ GHC.GhcT $ \s -> MTLAdapter (g s)
unwrap m = unMTLA . GHC.unGhcT (unGhcT m)

instance (MonadIO m, MonadCatch m, MonadMask m) => GHC.ExceptionMonad (GhcT m) where
gcatch = catch
Expand Down

0 comments on commit 199d924

Please sign in to comment.