diff --git a/source/Network/Xmpp/Concurrent.hs b/source/Network/Xmpp/Concurrent.hs index c40090f..9ff6ccc 100644 --- a/source/Network/Xmpp/Concurrent.hs +++ b/source/Network/Xmpp/Concurrent.hs @@ -113,12 +113,13 @@ newSession stream config = runErrorT $ do ] (kill, wLock, streamState, readerThread) <- ErrorT $ startThreadsWith stanzaHandler eh stream writer <- lift $ forkIO $ writeWorker outC wLock + idGen <- liftIO $ sessionStanzaIDs config return $ Session { stanzaCh = stanzaChan , outCh = outC , iqHandlers = iqHandlers , writeRef = wLock , readerThread = readerThread - , idGenerator = sessionStanzaIDs config + , idGenerator = idGen , streamRef = streamState , eventHandlers = eh , stopThreads = kill >> killThread writer diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs index 19c9f0e..5ad805d 100644 --- a/source/Network/Xmpp/Types.hs +++ b/source/Network/Xmpp/Types.hs @@ -1100,7 +1100,7 @@ data SessionConfiguration = SessionConfiguration -- | Handler to be run when the session ends (for whatever reason). , sessionClosedHandler :: XmppFailure -> IO () -- | Function to generate the stream of stanza identifiers. - , sessionStanzaIDs :: IO StanzaID + , sessionStanzaIDs :: IO (IO StanzaID) , extraStanzaHandlers :: [StanzaHandler] } @@ -1109,10 +1109,10 @@ instance Default SessionConfiguration where , sessionClosedHandler = \_ -> return () , sessionStanzaIDs = do idRef <- newTVarIO 1 - atomically $ do + return . atomically $ do curId <- readTVar idRef writeTVar idRef (curId + 1 :: Integer) - return . read. show $ curId + return . StanzaID . Text.pack . show $ curId , extraStanzaHandlers = [] }