Skip to content

Instantly share code, notes, and snippets.

@drchaos
Last active July 8, 2022 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drchaos/e87a623a03e98f517ebb16c7fa6cfd4a to your computer and use it in GitHub Desktop.
Save drchaos/e87a623a03e98f517ebb16c7fa6cfd4a to your computer and use it in GitHub Desktop.
-- 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