Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- wait :: String -> Int -> IO ()
- waitWith :: EventHandlers -> Int -> String -> Int -> IO ()
- data EventHandlers = EventHandlers {
- createdSocket :: IO ()
- delaying :: IO ()
- restarting :: IO ()
- defaultDelay :: Int
Simple Wait Api
wait
will attempt to connect to the given host and port repeated every
10 milliseconds until it is successful. It will throw an IOError
if the
host cannot be resolved.
A typical use case is to call wait
in test code to wait for a server to
start before trying to connect. For example:
void $ forkIO $ Warp.run 7000 app -- Wait for the server to start listening on the socket wait "127.0.0.1" 7000 -- Communicate with the server
If you would like to control the delay or understand how many connection
attempts were made use waitWith
.
Since 0.0.0.1
Advanced Wait Api
:: EventHandlers | A record of IO actions that are called during sp |
-> Int | Microseconds to delay |
-> String | Host |
-> Int | Port |
-> IO () |
data EventHandlers Source #
The EventHandlers
is a record of IO
actions that are called when
interesting events occur in the lifecycle of the waitWith
loop.
One can pass in custom EventHandlers
values to implement logging
and other forms of instrumentation.
For example for debug one could print out each step using:
printHandlers = EventHandlers { createdSocket = putStrLn "createdSocket" , delaying = putStrLn "delaying" , restarting = putStrLn "restarting" }
EventHandlers | |
|
Instances
Semigroup EventHandlers Source # | |
Defined in Network.Socket.Wait (<>) :: EventHandlers -> EventHandlers -> EventHandlers # sconcat :: NonEmpty EventHandlers -> EventHandlers # stimes :: Integral b => b -> EventHandlers -> EventHandlers # | |
Monoid EventHandlers Source # | |
Defined in Network.Socket.Wait mempty :: EventHandlers # mappend :: EventHandlers -> EventHandlers -> EventHandlers # mconcat :: [EventHandlers] -> EventHandlers # |
defaultDelay :: Int Source #
The default delay between retries is 10000 microseconds (10 ms)