purescript-metrics/src/System/Metrics/Counter.purs

26 lines
912 B
Plaintext
Raw Normal View History

2017-11-20 17:06:31 +05:30
module System.Metrics.Counter (Counter, new, read, reset, inc) where
2017-11-15 18:00:34 +05:30
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Ref (REF)
import Data.Function.Uncurried (Fn2, runFn2)
import Prelude (Unit)
2017-11-20 17:06:31 +05:30
-- | A mutable, integer valued counter.
2017-11-15 18:00:34 +05:30
foreign import data Counter :: Type
foreign import _new :: forall eff. Eff (ref :: REF | eff) Counter
2017-11-20 17:06:31 +05:30
-- | Returns the current value of the counter.
2017-11-15 18:00:34 +05:30
foreign import read :: forall eff. Counter -> Eff (ref :: REF | eff) Int
2017-11-20 17:06:31 +05:30
-- | Resets the counter value to zero.
2017-11-15 18:00:34 +05:30
foreign import reset :: forall eff. Counter -> Eff (ref :: REF | eff) Unit
foreign import _inc :: forall eff. Fn2 Counter Int (Eff (ref :: REF | eff) Unit)
2017-11-20 17:06:31 +05:30
-- | Creates a new counter with zero value.
2017-11-15 18:00:34 +05:30
new :: forall eff. Eff (ref :: REF | eff) Counter
new = _new
2017-11-20 17:06:31 +05:30
-- | Increments the counter value by the given count.
2017-11-15 18:00:34 +05:30
inc :: forall eff. Counter -> Int -> Eff (ref :: REF | eff) Unit
inc c = runFn2 _inc c