rapid
rapid copied to clipboard
Need to Ctrl-C in GHCI every other time (Windows)
Hi, I have an update function like this:
update :: IO ()
update =
Rapid.rapid 0 $ \r -> do
env <- getEnvironment
dbConn <- DB.newRedisConn env
Rapid.restart r "webserver" $ do
putStrLn "(re)starting the webserver"
Main.startServer 3000 dbConn
where startServer runs Snap's httpServe (config defaultConfig) (routes conn)
Every 2nd time I run the update function in ghci, I have to press Ctrl-C to access ghci and run the update function again. This is on Windows 10.
Thanks for your report. Note that with your setup you probably have two Redis connections open every second time you run the update
action. That's why you shouldn't acquire resources directly in the rapid
block. If you want to open the connection once and keep it open use createRef
. If you want to reopen it every time, open it from within the restart
action, because that one will only have one instance running at any point in time.
Does that fix your problem?
OK, I tried this:
update :: IO ()
update = do
env <- getEnvironment
Rapid.rapid 0 $ \r -> do
dbConn <- Rapid.createRef r "dbConn" $
DB.newRedisConn env
Rapid.restart r "webserver" $ do
putStrLn "(re)starting the webserver"
Main.startServer 3000 dbConn
But the problem persists.