withApplication :: Application -> IO a -> IO a
withApplication app action = do
  started <- newEmptyMVar
  stopped <- newEmptyMVar
  threadId <- forkIO $
    runSettings defaultSettings {settingsPort = 3000, settingsBeforeMainLoop = putMVar started ()} app `finally` putMVar stopped ()
  takeMVar started
  action `finally` (killThread threadId >> takeMVar stopped)
withApplication :: Application -> IO a -> IO a
withApplication app action = do
  started <- newEmptyMVar
  stopped <- newEmptyMVar
  threadId <- forkIO $
    runSettings defaultSettings {settingsPort = 3000, settingsBeforeMainLoop = putMVar started ()} app `finally` putMVar stopped ()
  takeMVar started
  action `finally` (killThread threadId >> takeMVar stopped)
withApplication app action = do
  started <- newEmptyMVar
  stopped <- newEmptyMVar
  threadId <- forkIO $
    runSettings defaultSettings {settingsPort = 3000, settingsBeforeMainLoop = putMVar started ()} app `finally` putMVar stopped ()
  takeMVar started
  action `finally` (killThread threadId >> takeMVar stopped)