network-wait-0.2.0.0: Lightweight library for waiting on networked services to become available.
Safe HaskellNone
LanguageHaskell2010

Network.Wait

Description

This module contains computations which wait for some networked service to become available, subject to some retry policy from Control.Retry. The waitSocketWith function is the most general function exported by this module, but several variants exist for convenience. You may wish to start out with e.g. waitTcp or waitSocket initially and move on to the more feature-rich variants if you need their functionality.

Synopsis

TCP

waitTcp :: (MonadIO m, MonadMask m) => RetryPolicyM m -> HostName -> ServiceName -> m Socket Source #

waitTcp retryPolicy hostName serviceName is a variant of waitTcpWith which does not install any additional handlers.

waitTcp retryPolicyDefault "localhost" "80"

waitTcpVerbose :: (MonadIO m, MonadMask m) => (String -> m ()) -> RetryPolicyM m -> HostName -> ServiceName -> m Socket Source #

waitTcpVerbose outputHandler retryPolicy addrInfo is a variant of waitTcpVerboseFormat which catches all exceptions derived from SomeException and formats retry attempt information using defaultLogMsg before passing the resulting String to out.

waitTcpVerbose putStrLn retryPolicyDefault "localhost" "80"

waitTcpVerboseFormat :: forall e m. (MonadIO m, MonadMask m, Exception e) => (Bool -> e -> RetryStatus -> m ()) -> RetryPolicyM m -> HostName -> ServiceName -> m Socket Source #

waitTcpVerboseFormat outputHandler retryPolicy addrInfo is a variant of waitTcpWith which installs an extra handler based on logRetries which passes status information for each retry attempt to outputHandler.

waitTcpVerboseFormat @SomeException
     (\b ex st -> putStrLn $ defaultLogMsg b ex st)
     retryPolicyDefault "localhost" "80"

waitTcpWith :: (MonadIO m, MonadMask m) => [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> HostName -> ServiceName -> m Socket Source #

waitTcpWith extraHandlers retryPolicy hostName serviceName is a variant of waitSocketWith which constructs a suitable AddrInfo value for a TCP socket from hostName and serviceName.

Sockets

waitSocket :: (MonadIO m, MonadMask m) => RetryPolicyM m -> AddrInfo -> m Socket Source #

waitSocket retryPolicy addrInfo is a variant of waitSocketWith which does not install any additional exception handlers.

waitSocketVerbose :: (MonadIO m, MonadMask m) => (String -> m ()) -> RetryPolicyM m -> AddrInfo -> m Socket Source #

waitSocketVerbose outputHandler retryPolicy addrInfo is a variant of waitSocketVerboseFormat which catches all exceptions derived from SomeException and formats retry attempt information using defaultLogMsg before passing the resulting String to out.

waitSocketVerboseFormat :: forall e m. (MonadIO m, MonadMask m, Exception e) => (Bool -> e -> RetryStatus -> m ()) -> RetryPolicyM m -> AddrInfo -> m Socket Source #

waitSocketVerboseFormat outputHandler retryPolicy addrInfo is a variant of waitSocketWith which installs an extra handler based on logRetries which passes status information for each retry attempt to outputHandler.

waitSocketWith :: (MonadIO m, MonadMask m) => [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> AddrInfo -> m Socket Source #

waitSocketWith extraHandlers retryPolicy addrInfo will attempt to connect to addrInfo. If the connection fails, retryPolicy is used to determine whether (and how often) this function should attempt to retry establishing the connection. By default, this function will retry after all exceptions (except for those given by skipAsyncExceptions). This behaviour may be customised with extraHandlers which are installed after skipAsyncExceptions, but before the default exception handler. The extraHandlers may also be used to report retry attempts to e.g. the standard output or a logger.

Utility

recoveringWith :: (MonadIO m, MonadMask m) => [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> m a -> m a Source #

recoveringWith extraHandlers retryPolicy action will attempt to run action. If the action fails, retryPolicy is used to determine whether (and how often) this function should attempt to retry action. By default, this function will retry after all exceptions (except for those given by skipAsyncExceptions). This behaviour may be customised with extraHandlers which are installed after skipAsyncExceptions, but before the default exception handler. The extraHandlers may also be used to report retry attempts to e.g. the standard output or a logger.