-- |Description: AtomicState Interpreters
module Polysemy.Conc.AtomicState where

import Polysemy.AtomicState (runAtomicStateTVar)

-- |Convenience wrapper around 'runAtomicStateTVar' that creates a new 'TVar'.
interpretAtomic ::
   a r .
  Member (Embed IO) r =>
  a ->
  InterpreterFor (AtomicState a) r
interpretAtomic :: a -> InterpreterFor (AtomicState a) r
interpretAtomic a
initial Sem (AtomicState a : r) a
sem = do
  TVar a
tv <- a -> Sem r (TVar a)
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO a
initial
  TVar a -> Sem (AtomicState a : r) a -> Sem r a
forall (r :: [Effect]) 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 #-}