From 0a5e47f477bdbbb546ab7c113b3ae856ba2ccd89 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Mon, 21 Sep 2020 22:36:15 +0000 Subject: [PATCH 1/2] docs: add lens utils function example This change document lens function usage for user not familiar with lens operators. --- Network/IRC/Client.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Network/IRC/Client.hs b/Network/IRC/Client.hs index abae449..c1c5ea3 100644 --- a/Network/IRC/Client.hs +++ b/Network/IRC/Client.hs @@ -16,6 +16,12 @@ -- > let cfg = defaultInstanceConfig nick & handlers %~ (yourCustomEventHandlers:) -- > runClient conn cfg () -- +-- The '&' and '%~' comes from the lens library, and they can be replaced by the +-- provided utility functions 'get' and 'set'. For example: +-- +-- > let defaultCfg = defaultInstanceConfig nick +-- > let cfg = set handlers (get handlers defaultCfg <> yourCustomEvenHandlers) defaultCfg + -- You shouldn't really need to tweak anything other than the event -- handlers, as everything has been designed to be as simple as -- possible. From 3870142bb643689569ad65d7333df20dea8e9b6d Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Mon, 21 Sep 2020 22:50:36 +0000 Subject: [PATCH 2/2] docs: add typical outside usage form --- Network/IRC/Client.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Network/IRC/Client.hs b/Network/IRC/Client.hs index c1c5ea3..d2329e8 100644 --- a/Network/IRC/Client.hs +++ b/Network/IRC/Client.hs @@ -280,6 +280,22 @@ runClient cconf iconf ustate = newIRCState cconf iconf ustate >>= runClientWith -- Multiple clients should not be run with the same 'IRCState'. The -- utility of this is to be able to run @IRC s a@ actions in order to -- interact with the client from the outside. +-- +-- Typical usage will be of this form: +-- +-- > ircThread :: IRCState s -> IO () +-- > ircThread state = Control.Exception.handle doReconnect (runClientWith state) +-- > where +-- > doReconnect :: Disconnect -> IO () +-- > doReconnect e = do +-- > print ("irc client exited: " <> show e) +-- > threadDelay 1000000 >> runIRCAction reconnect state >> ircThread state +-- +-- > mainThread :: ConnectionConfig s -> InstanceConfig s -> IO () +-- > mainThread conn cfg = do +-- > state <- newIRCState conn cfg () +-- > withAsync (ircThread state) (const (runMain state)) +-- runClientWith :: MonadIO m => IRCState s -> m () runClientWith = runIRCAction runner