module Text.Show.Text.Control.Concurrent (
showbThreadIdPrec
, showbThreadStatusPrec
, showbBlockReason
) where
import Data.Text.Lazy.Builder (Builder, fromString)
import GHC.Conc (BlockReason(..), ThreadId, ThreadStatus(..))
import GHC.Show (appPrec)
import qualified Prelude as P
import Prelude hiding (Show)
import Text.Show.Text.Class (Show(showb, showbPrec), showbParen)
import Text.Show.Text.Utils ((<>))
showbThreadIdPrec :: Int -> ThreadId -> Builder
showbThreadIdPrec p ti = fromString $ P.showsPrec p ti ""
showbThreadStatusPrec :: Int -> ThreadStatus -> Builder
showbThreadStatusPrec _ ThreadRunning = "ThreadRunning"
showbThreadStatusPrec _ ThreadFinished = "ThreadFinished"
showbThreadStatusPrec p (ThreadBlocked br)
= showbParen (p > appPrec) $ "ThreadBlocked " <> showbBlockReason br
showbThreadStatusPrec _ ThreadDied = "ThreadDied"
showbBlockReason :: BlockReason -> Builder
showbBlockReason BlockedOnMVar = "BlockedOnMVar"
showbBlockReason BlockedOnBlackHole = "BlockedOnBlackHole"
showbBlockReason BlockedOnException = "BlockedOnException"
showbBlockReason BlockedOnSTM = "BlockedOnSTM"
showbBlockReason BlockedOnForeignCall = "BlockedOnForeignCall"
showbBlockReason BlockedOnOther = "BlockedOnOther"
instance Show ThreadId where
showbPrec = showbThreadIdPrec
instance Show ThreadStatus where
showbPrec = showbThreadStatusPrec
instance Show BlockReason where
showb = showbBlockReason