从
http://happstack.com/docs/crashcourse/HappstackState.html
当我运行服务器时,窥视计数器增加
- 1当我偷看
- 2 当我不偷看时
有问题的相关代码是:
handlers :: ServerPart Response
handlers =
msum [ dir "peek" $ do c <- query PeekCounter
ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
, do c <- update (AddCounter 1)
ok $ toResponse $ "New count is: " ++ show (unCounter c)
]
但是,当我将其修改为
handlers :: ServerPart Response
handlers =
msum [ dir "peek" $ do c <- query PeekCounter
ok $ toResponse $ "peeked at the count and saw: " ++ show (unCounter c)
, do ok $ toResponse $ "Stop here."
, do c <- update (AddCounter 1)
ok $ toResponse $ "New count is: " ++ show (unCounter c)
]
计数器增加
- 0 当我偷看
- 1 当我不偷看时
这是预期的行为吗?即使我偷看,感觉好像 msum 中的第二个 monad 正在“泄漏”。