Skip to content

Instantly share code, notes, and snippets.

@jfischoff
Created June 11, 2017 01:06
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 jfischoff/995e465bf4a0cce57d3d607b76ebd097 to your computer and use it in GitHub Desktop.
Save jfischoff/995e465bf4a0cce57d3d607b76ebd097 to your computer and use it in GitHub Desktop.
waitForPort :: Int -> IO ()
waitForPort port = handle (\(_ :: IOException) -> threadDelay 10000 >> waitForDB port) $ do
let hints = defaultHints
{ addrFlags =
[ AI_NUMERICHOST
, AI_NUMERICSERV
]
, addrSocketType = Stream
}
addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just $ show port)
bracket (socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr))
close
$ \sock -> connect sock $ addrAddress addr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment