module TimerWheel.Internal.Supply ( Supply, new, next, ) where import Data.Atomics.Counter (AtomicCounter, incrCounter, newCounter) import Data.Coerce (coerce) newtype Supply = Supply AtomicCounter new :: IO Supply new :: IO Supply new = coerce :: forall a b. Coercible a b => a -> b coerce (Int -> IO AtomicCounter newCounter Int 0) next :: Supply -> IO Int next :: Supply -> IO Int next = coerce :: forall a b. Coercible a b => a -> b coerce (Int -> AtomicCounter -> IO Int incrCounter Int 1) {-# INLINE next #-}