Dan*_*ton 12 resources haskell asynchronous exception
假设我有一些像这样编写的代码:
import Control.Exception (bracketOnError, finally, mask)
import Client (acquireB, releaseB, doStuff) -- theoretical
import MyStuff (preliminary, doMoreStuff) -- theoretical
clientAction = bracketOnError acquireB releaseB $ \b ->
doStuff b
return (b, releaseB b)
myAction = mask $ \restore ->
a <- preliminary
(thing, releaseThing) <- restore clientAction
doMoreStuff a thing `finally` releaseThing
Run Code Online (Sandbox Code Playgroud)
我必须做一些preliminary事情,我的客户获得b然后必须doStuff与b,然后我必须doMoreStuff与b.并且b需要释放,即使发生异步异常.但我不知道如何发布b,所以我的客户告诉我如何.以这种方式编写,b如果在"我们的"代码中发生异常,我们都准备发布.
我的问题是:异步异常是否有可能导致releaseB不执行?具体来说,"我的代码"和"我的客户端代码"之间是否存在间隙,异步异常可以挤入其中?让我内联clientAction并bracketOnException解释.
myAction = mask $ \restore -> do
a <- preliminary
(thing, releaseThing) <- restore $ mask $ \restore2 -> do
b <- acquireB
restore2 (doStuff b >> return (b, releaseB b))
`onException` releaseB b
doMoreStuff a thing `finally` releaseThing
Run Code Online (Sandbox Code Playgroud)
关注的是:这里有片刻吗?
... restore $ mask ...
Run Code Online (Sandbox Code Playgroud)
当客户端mask被解除时,但在我restore周围结束之前,异常可能会被偷偷摸摸?