Last active
July 8, 2022 07:37
-
-
Save drchaos/e87a623a03e98f517ebb16c7fa6cfd4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ghc 8.10.7 | |
-- Server code | |
runServer ctx = do | |
bracket (spawnWorkers ctx) (mapM_ killThread) $ const | |
liftIO $ useContext ctx -- At this point context looks uninialized | |
where | |
spawnWorkers = replicateM (ctx ^. number) (fork $ worker ctx) | |
-- The code that works with optimization disabled but but don't with optimization enabled | |
-- ... | |
ctx <- createCtx | |
-- ... | |
runServer ctx | |
-- Those code snippets work regardless optimizations status | |
-- ... | |
bracket createCtx freeCtx $ \ctx -> do | |
-- ... | |
runServer ctx | |
-- ... | |
ctx <- createCtx | |
-- ... | |
hanlde (h ctx) $ runServer ctx | |
where | |
h ctx@Ctx{..} (e::SomeException) = do | |
log $ show ctx ^. member | |
throwIO e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment