on master help sign in
adding a missing module.
commit2c1d2c8ad542ac546441894811629eee9d94522c authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 15 Aug 2014, 16:17 (12 years ago) parent66003d4
1 file changed+24
warp/Network/Wai/Handler/Warp/Counter.hs+24
warp/Network/Wai/Handler/Warp/Counter.hsnew file+24
@@ -0,0 +1,24 @@
1+module Network.Wai.Handler.Warp.Counter (
2+ Counter
3+ , newCounter
4+ , isZero
5+ , increase
6+ , decrease
7+ ) where
8+
9+import Network.Wai.Handler.Warp.IORef
10+import Control.Applicative ((<$>))
11+
12+newtype Counter = Counter (IORef Int)
13+
14+newCounter :: IO Counter
15+newCounter = Counter <$> newIORef 0
16+
17+isZero :: Counter -> IO Bool
18+isZero (Counter ref) = (== 0) <$> readIORef ref
19+
20+increase :: Counter -> IO ()
21+increase (Counter ref) = atomicModifyIORef' ref $ \x -> (x + 1, ())
22+
23+decrease :: Counter -> IO ()
24+decrease (Counter ref) = atomicModifyIORef' ref $ \x -> (x - 1, ())