rapid icon indicating copy to clipboard operation
rapid copied to clipboard

Need to Ctrl-C in GHCI every other time (Windows)

Open jmn opened this issue 7 years ago • 2 comments

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.

jmn avatar Jul 26 '17 10:07 jmn

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?

esoeylemez avatar Jul 28 '17 11:07 esoeylemez

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.

jmn avatar Aug 01 '17 19:08 jmn