Created
June 11, 2017 01:06
-
-
Save jfischoff/995e465bf4a0cce57d3d607b76ebd097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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