amqp 0.2.6 → 0.2.7
raw patch · 2 files changed
+23/−3 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.AMQP: addConnectionClosedHandler :: Connection -> Bool -> IO () -> IO ()
Files
- Network/AMQP.hs +22/−2
- amqp.cabal +1/−1
Network/AMQP.hs view
@@ -52,6 +52,7 @@ openConnection, openConnection', closeConnection,+ addConnectionClosedHandler, -- * Channel Channel,@@ -543,6 +544,7 @@ connClosed :: MVar (Maybe String), connClosedLock :: MVar (), -- used by closeConnection to block until connection-close handshake is complete connWriteLock :: MVar (), -- to ensure atomic writes to the socket+ connClosedHandlers :: MVar [IO ()], lastChannelID :: MVar Int --for auto-incrementing the channelIDs } @@ -626,7 +628,8 @@ cClosed <- newMVar Nothing writeLock <- newMVar () ccl <- newEmptyMVar- let conn = Connection sock connChannels (fromIntegral maxFrameSize) cClosed ccl writeLock lastChanID+ connClosedHandlers <- newMVar []+ let conn = Connection sock connChannels (fromIntegral maxFrameSize) cClosed ccl writeLock connClosedHandlers lastChanID --spawn the connectionReceiver forkIO $ CE.finally (connectionReceiver conn) @@ -643,6 +646,10 @@ -- mark connection as closed, so all pending calls to 'closeConnection' can now return tryPutMVar ccl ()+ + -- notify connection-close-handlers+ withMVar connClosedHandlers sequence+ ) return conn@@ -678,10 +685,23 @@ return () ) - -- wait for connection_close_ok by the server+ -- wait for connection_close_ok by the server; this MVar gets filled in the CE.finally handler in openConnection' readMVar $ connClosedLock c return () ++-- | @addConnectionClosedHandler conn ifClosed handler@ adds a @handler@ that will be called after the connection is closed (either by calling @closeConnection@ or by an exception). If the @ifClosed@ parameter is True and the connection is already closed, the handler will be called immediately. If @ifClosed == False@ and the connection is already closed, the handler will never be called+addConnectionClosedHandler :: Connection -> Bool -> IO () -> IO ()+addConnectionClosedHandler conn ifClosed handler = do+ withMVar (connClosed conn) $ \cc -> do+ case cc of+ -- connection is already closed, so call the handler directly+ Just _ | ifClosed == True -> handler+ + -- otherweise add it to the list+ _ -> modifyMVar_ (connClosedHandlers conn) $ \old -> return $ handler:old+ +
amqp.cabal view
@@ -1,5 +1,5 @@ Name: amqp -Version: 0.2.6 +Version: 0.2.7 Synopsis: Client library for AMQP servers (currently only RabbitMQ) Description: Client library for AMQP servers (currently only RabbitMQ) License: BSD3