From cc7b1fd63caebdac7a77e1e9c91100e340885d9e Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Sun, 7 Nov 2021 21:01:26 +0700 Subject: [PATCH] BrokerClient: correct sqnum update --- src/ATrade/Broker/Client.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ATrade/Broker/Client.hs b/src/ATrade/Broker/Client.hs index 0a658dc..49da56d 100644 --- a/src/ATrade/Broker/Client.hs +++ b/src/ATrade/Broker/Client.hs @@ -124,12 +124,13 @@ notificationThread clientIdentity callbacks ctx ep idCounter cmdVar killMv secPa resp <- takeMVar respVar case resp of (ResponseNotifications ns) -> do - case lastMay ns of - Just n -> atomicWriteIORef notifSqnumRef (nextSqnum $ getNotificationSqnum n) - Nothing -> return () - return () + forM_ ns $ \notif -> do + lastSqnum <- readIORef notifSqnumRef + when (getNotificationSqnum notif >= lastSqnum) $ do + forM_ callbacks $ \c -> c notif + atomicWriteIORef notifSqnumRef (nextSqnum lastSqnum) (ResponseError msg) -> warningM "Broker.Client" $ "ResponseError: " <> T.unpack msg - _ -> warningM "Broker.Client" $ "Unknown error when requesting notifications" + _ -> warningM "Broker.Client" "Unknown error when requesting notifications" else do msg <- receiveMulti sock case msg of