ekg/System/Remote/Label.hs
Iustin Pop 42357a50ea Add a Label metric type
This is used to hold Text values, which are free-form and can be used
for (e.g.) hostname, command line, etc.

I've used Text, but I'm not sure whether String would make more sense
for (what are supposed to be) such small values.
2012-04-17 22:21:30 +02:00

27 lines
806 B
Haskell

{-# LANGUAGE BangPatterns #-}
-- | This module defines a type for mutable, string-valued labels.
-- Labels are variable values and can be used to track e.g. the
-- command line arguments or other free-form values. All operations on
-- labels are thread-safe.
module System.Remote.Label
(
Label
, set
, modify
) where
import Data.IORef (atomicModifyIORef)
import qualified Data.Text as T
import System.Remote.Label.Internal
-- | Set the label to the given value.
set :: Label -> T.Text -> IO ()
set (C ref) !i = atomicModifyIORef ref $ \ _ -> (i, ())
-- | Set the label to the result of applying the given function to the
-- value.
modify :: (T.Text -> T.Text) -> Label -> IO ()
modify f (C ref) = do
!_ <- atomicModifyIORef ref $ \ i -> let i' = f i in (i', i')
return ()