Skip to content

Commit

Permalink
Add unliftio example in withPingPong docs
Browse files Browse the repository at this point in the history
See #246
  • Loading branch information
jaspervdj committed Jan 25, 2024
1 parent cbba20b commit 2474e53
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Network/WebSockets/Connection/PingPong.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ defaultPingPongOptions = PingPongOptions {
pingAction = return ()
}

-- | Run an application with ping-pong enabled. Raises PongTimeout if a pong is not received.
--
-- | Run an application with ping-pong enabled. Raises 'PongTimeout' if a pong
-- is not received.
--
-- Can used with Client and Server connections.
--
-- The implementation uses multiple threads, so if you want to call this from a
-- Monad other than 'IO', we recommend using
-- [unliftio](https://hackage.haskell.org/package/unliftio), e.g. using a
-- wrapper like this:
--
-- > withPingPongUnlifted
-- > :: MonadUnliftIO m
-- > => PingPongOptions -> Connection -> (Connection -> m ()) -> m ()
-- > withPingPongUnlifted options connection app = withRunInIO $ \run ->
-- > withPingPong options connection (run . app)
withPingPong :: PingPongOptions -> Connection -> (Connection -> IO ()) -> IO ()
withPingPong options connection app = void $
withAsync (app connection) $ \appAsync -> do
Expand Down

0 comments on commit 2474e53

Please sign in to comment.