1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Merge pull request #2455 from github/signal-handling

Shutdown gracefully on SIGINT and SIGTERM
This commit is contained in:
Josh Vera 2019-03-18 20:00:36 -04:00 committed by GitHub
commit 10d80acebd
2 changed files with 13 additions and 0 deletions

View File

@ -54,6 +54,7 @@ common dependencies
, network
, recursion-schemes
, scientific
, safe-exceptions
, semilattices
, text
, these

View File

@ -6,6 +6,7 @@
module Control.Effect.Catch
( Catch (..)
, catch
, catchSync
, runCatch
, CatchC (..)
) where
@ -14,6 +15,7 @@ import Control.Effect.Carrier
import Control.Effect.Reader
import Control.Effect.Sum
import qualified Control.Exception as Exc
import Control.Exception.Safe (isSyncException)
import Control.Monad.IO.Class
data Catch m k
@ -39,6 +41,16 @@ catch :: (Member Catch sig, Carrier sig m, Exc.Exception e)
-> m a
catch go cleanup = send (CatchIO go cleanup pure)
catchSync :: (Member Catch sig, Carrier sig m, Exc.Exception e, MonadIO m)
=> m a
-> (e -> m a)
-> m a
catchSync f g = f `catch` \e ->
if isSyncException e
then g e
-- intentionally rethrowing an async exception synchronously,
-- since we want to preserve async behavior
else liftIO (Exc.throw e)
-- | Evaulate a 'Catch' effect.
runCatch :: (forall x . m x -> IO x)