module Polysemy.Conc.AtomicState where
import Control.Concurrent.STM (newTVarIO)
interpretAtomic ::
∀ a r .
Member (Embed IO) r =>
a ->
InterpreterFor (AtomicState a) r
interpretAtomic :: forall a (r :: EffectRow).
Member (Embed IO) r =>
a -> InterpreterFor (AtomicState a) r
interpretAtomic a
initial Sem (AtomicState a : r) a
sem = do
TVar a
tv <- IO (TVar a) -> Sem r (TVar a)
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed (a -> IO (TVar a)
forall a. a -> IO (TVar a)
newTVarIO a
initial)
TVar a -> Sem (AtomicState a : r) a -> Sem r a
forall (r :: EffectRow) s a.
Member (Embed IO) r =>
TVar s -> Sem (AtomicState s : r) a -> Sem r a
runAtomicStateTVar TVar a
tv Sem (AtomicState a : r) a
sem
{-# inline interpretAtomic #-}