-- | Lifted "Control.Concurrent.Chan.Strict".
--
-- @since 2.4.0.0
module Effectful.Concurrent.Chan.Strict
  ( -- * Effect
    Concurrent

    -- ** Handlers
  , runConcurrent

    -- * Chan
  , Chan'
  , newChan'
  , writeChan'
  , readChan'
  , dupChan'
  , getChan'Contents
  , writeList2Chan'
  ) where

import Control.Concurrent.Chan.Strict (Chan')
import Control.Concurrent.Chan.Strict qualified as C

import Effectful
import Effectful.Concurrent.Effect
import Effectful.Dispatch.Static

-- | Lifted 'C.newChan''.
newChan' :: Concurrent :> es => Eff es (Chan' a)
newChan' :: forall (es :: [Effect]) a. (Concurrent :> es) => Eff es (Chan' a)
newChan' = IO (Chan' a) -> Eff es (Chan' a)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ IO (Chan' a)
forall a. IO (Chan' a)
C.newChan'

-- | Lifted 'C.writeChan''.
writeChan' :: Concurrent :> es => Chan' a -> a -> Eff es ()
writeChan' :: forall (es :: [Effect]) a.
(Concurrent :> es) =>
Chan' a -> a -> Eff es ()
writeChan' Chan' a
c = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> (a -> IO ()) -> a -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chan' a -> a -> IO ()
forall a. Chan' a -> a -> IO ()
C.writeChan' Chan' a
c

-- | Lifted 'C.readChan''.
readChan' :: Concurrent :> es => Chan' a -> Eff es a
readChan' :: forall (es :: [Effect]) a.
(Concurrent :> es) =>
Chan' a -> Eff es a
readChan' = IO a -> Eff es a
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO a -> Eff es a) -> (Chan' a -> IO a) -> Chan' a -> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chan' a -> IO a
forall a. Chan' a -> IO a
C.readChan'

-- | Lifted 'C.dupChan''.
dupChan' :: Concurrent :> es => Chan' a -> Eff es (Chan' a)
dupChan' :: forall (es :: [Effect]) a.
(Concurrent :> es) =>
Chan' a -> Eff es (Chan' a)
dupChan' = IO (Chan' a) -> Eff es (Chan' a)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Chan' a) -> Eff es (Chan' a))
-> (Chan' a -> IO (Chan' a)) -> Chan' a -> Eff es (Chan' a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chan' a -> IO (Chan' a)
forall a. Chan' a -> IO (Chan' a)
C.dupChan'

-- | Lifted 'C.getChan'Contents'.
getChan'Contents :: Concurrent :> es => Chan' a -> Eff es [a]
getChan'Contents :: forall (es :: [Effect]) a.
(Concurrent :> es) =>
Chan' a -> Eff es [a]
getChan'Contents = IO [a] -> Eff es [a]
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO [a] -> Eff es [a])
-> (Chan' a -> IO [a]) -> Chan' a -> Eff es [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chan' a -> IO [a]
forall a. Chan' a -> IO [a]
C.getChan'Contents

-- | Lifted 'C.writeList2Chan''.
writeList2Chan' :: Concurrent :> es => Chan' a -> [a] -> Eff es ()
writeList2Chan' :: forall (es :: [Effect]) a.
(Concurrent :> es) =>
Chan' a -> [a] -> Eff es ()
writeList2Chan' Chan' a
c = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> ([a] -> IO ()) -> [a] -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chan' a -> [a] -> IO ()
forall a. Chan' a -> [a] -> IO ()
C.writeList2Chan' Chan' a
c