polysemy-conc-0.5.0.0: Polysemy Effects for Concurrency
Safe HaskellNone
LanguageHaskell2010

Polysemy.Conc.Effect.Interrupt

Description

 
Synopsis

Documentation

data Interrupt :: Effect where Source #

The interrupt handler effect allows three kinds of interaction for interrupt signals:

  • Execute a callback when a signal is received
  • Block a thread until a signal is received
  • Kill a thread when a signal is received

For documentation on the constructors, see the module Polysemy.Conc.Effect.Interrupt.

import qualified Polysemy.Conc.Effect.Interrupt as Interrupt

prog = do
  Interrupt.register "task 1" (putStrLn "interrupted")
  Interrupt.killOnQuit $ forever do
   doSomeWork

Constructors

Register :: Text -> IO () -> Interrupt m ()

Add a computation to be executed on interrupt, using the first argument as a key.

Unregister :: Text -> Interrupt m ()

Remove the previously added handler with the given key.

Quit :: Interrupt m ()

Manually trigger the interrupt.

WaitQuit :: Interrupt m ()

Block until an interrupt is triggered.

Interrupted :: Interrupt m Bool

Indicate whether an interrupt was triggered.

KillOnQuit :: Text -> m a -> Interrupt m (Maybe a)

Execute a computation, waiting for it to finish, killing its thread on interrupt.

Instances

Instances details
type DefiningModule Interrupt Source # 
Instance details

Defined in Polysemy.Conc.Effect.Interrupt

type DefiningModule Interrupt = "Polysemy.Conc.Effect.Interrupt"

killOnQuit_ :: Member Interrupt r => Text -> Sem r a -> Sem r () Source #

Variant of killOnQuit that returns ().