From d4390c3e626f7576241aeb520e27729cf25e1871 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Thu, 5 Jul 2012 14:34:05 +0200 Subject: [PATCH] changed listenIQChan to return the current channel, if one --- source/Network/Xmpp/Concurrent/Monad.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Network/Xmpp/Concurrent/Monad.hs b/source/Network/Xmpp/Concurrent/Monad.hs index d29f5ab..960cb10 100644 --- a/source/Network/Xmpp/Concurrent/Monad.hs +++ b/source/Network/Xmpp/Concurrent/Monad.hs @@ -19,14 +19,14 @@ import Network.Xmpp.Concurrent.Types import Network.Xmpp.Monad --- | Register a new IQ listener. IQ requests matching the type and namespace --- will be put in the channel. --- --- Return the new channel or Nothing if this namespace/'IQRequestType' --- combination was alread handled. +-- | Retrieves an IQ listener channel. If the namespace/'IQRequestType' is not +-- already handled, a new 'TChan' is created and returned as a 'Right' value. +-- Otherwise, the already existing channel will be returned wrapped in a 'Left' +-- value. Note that the 'Left' channel might need to be duplicated in order not +-- to interfere with existing consumers. listenIQChan :: IQRequestType -- ^ Type of IQs to receive (@Get@ or @Set@) -> Text -- ^ Namespace of the child element - -> Xmpp (Maybe (TChan IQRequestTicket)) + -> Xmpp (Either (TChan IQRequestTicket) (TChan IQRequestTicket)) listenIQChan tp ns = do handlers <- asks iqHandlers liftIO . atomically $ do @@ -39,8 +39,8 @@ listenIQChan tp ns = do byNS writeTVar handlers (byNS', byID) return $ case present of - Nothing -> Just iqCh - Just _iqCh' -> Nothing + Nothing -> Right iqCh + Just iqCh' -> Left iqCh' -- | Get a duplicate of the stanza channel getStanzaChan :: Xmpp (TChan Stanza)