正常关闭进程

时间:2018-09-05 15:12:38

标签: haskell

当进程即将关闭时,我想关闭商店连接(添加close eventStoreConnection之类的功能):

main = do
     eventStoreConnection <- EventStore.connect EventStore.defaultSettings (EventStore.Static "127.0.0.1" 1113)
     scotty 3000 $ do
       get  "/health/liveness" $ do html "OK"
       post "/introduceIdea" $ do
          command <- jsonData
          liftIO $ persist eventStoreConnection command
          html "OK"

1 个答案:

答案 0 :(得分:3)

您可以使用bracket。喜欢:

let connect = EventStore.connect EventStore.defaultSettings (EventStore.Static "127.0.0.1" 1113))
bracket connect close $ \eventStoreConnection ->
    scotty 3000 $ ...