HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleport-utils-0.2.1.0Haskell2010

Network.Socket.Wait

  • 1 type
  • 3 values

Simple Wait Api

1 declaration
valuewait
  1. :: String

    Host

  2. -> Int

    Port

  3. -> IO ()
#

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

3 declarations
valuewaitWith
  1. :: EventHandlers IO

    A record of IO actions that are called during sp

  2. -> Int

    Microseconds to delay

  3. -> String

    Host

  4. -> Int

    Port

  5. -> IO ()
#

Advanced usage. In most situations calling wait will suffice. This allows one to customize the delay between retries and debug the behavior of the function. wait is defined as

   wait = waitWith mempty defaultDelay

Since 0.2.0.0

datadata EventHandlers (m :: Type -> Type)
#

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
     { acting     = putStrLn "acting"
     , delaying   = putStrLn "delaying"
     , restarting = putStrLn "restarting"
     }

Constructors

  • EventHandlers
    • connecting :: m ()

      Called before the socket is created for connection

    • delaying :: m ()

      Called after a failed attempt to connect before the thread is put to sleep.

    • restarting :: m ()

      Called before a recursive call to restart the connection attempt

Instances2Semigroup, Monoid
valuedefaultDelay :: Int
#

The default delay between retries is 10000 microseconds (10 ms)