module Ki.CancelToken
  ( CancelToken (..),
    newCancelToken,
  )
where

import Ki.Prelude

-- | A cancel token represents a request for /cancellation/; this request can be fulfilled by throwing the token as an
-- exception.
newtype CancelToken
  = CancelToken Int
  deriving stock (CancelToken -> CancelToken -> Bool
(CancelToken -> CancelToken -> Bool)
-> (CancelToken -> CancelToken -> Bool) -> Eq CancelToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelToken -> CancelToken -> Bool
$c/= :: CancelToken -> CancelToken -> Bool
== :: CancelToken -> CancelToken -> Bool
$c== :: CancelToken -> CancelToken -> Bool
Eq, Int -> CancelToken -> ShowS
[CancelToken] -> ShowS
CancelToken -> String
(Int -> CancelToken -> ShowS)
-> (CancelToken -> String)
-> ([CancelToken] -> ShowS)
-> Show CancelToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelToken] -> ShowS
$cshowList :: [CancelToken] -> ShowS
show :: CancelToken -> String
$cshow :: CancelToken -> String
showsPrec :: Int -> CancelToken -> ShowS
$cshowsPrec :: Int -> CancelToken -> ShowS
Show)
  deriving anyclass (Show CancelToken
Typeable CancelToken
Typeable CancelToken
-> Show CancelToken
-> (CancelToken -> SomeException)
-> (SomeException -> Maybe CancelToken)
-> (CancelToken -> String)
-> Exception CancelToken
SomeException -> Maybe CancelToken
CancelToken -> String
CancelToken -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: CancelToken -> String
$cdisplayException :: CancelToken -> String
fromException :: SomeException -> Maybe CancelToken
$cfromException :: SomeException -> Maybe CancelToken
toException :: CancelToken -> SomeException
$ctoException :: CancelToken -> SomeException
$cp2Exception :: Show CancelToken
$cp1Exception :: Typeable CancelToken
Exception)

newCancelToken :: IO CancelToken
newCancelToken :: IO CancelToken
newCancelToken =
  IO Int -> IO CancelToken
coerce IO Int
uniqueInt