Browse Source

BrokerClient: handle timeout in getNotifications

master
Denis Tereshkin 11 months ago
parent
commit
d4e3891145
  1. 4
      src/ATrade/Broker/Client.hs

4
src/ATrade/Broker/Client.hs

@ -278,6 +278,7 @@ bcGetNotifications clientIdentity idCounter notifSqnumRef cmdVar lastKnownNotifi
sqnum <- nextId idCounter sqnum <- nextId idCounter
notifSqnum <- nextSqnum <$> readIORef notifSqnumRef notifSqnum <- nextSqnum <$> readIORef notifSqnumRef
now <- getCurrentTime now <- getCurrentTime
result <- timeout 3000000 $ do
putMVar cmdVar (RequestNotifications (RequestId sqnum) clientIdentity notifSqnum, respVar, now) putMVar cmdVar (RequestNotifications (RequestId sqnum) clientIdentity notifSqnum, respVar, now)
resp <- takeMVar respVar resp <- takeMVar respVar
case resp of case resp of
@ -293,3 +294,6 @@ bcGetNotifications clientIdentity idCounter notifSqnumRef cmdVar lastKnownNotifi
return $ Left "requestId mismatch" return $ Left "requestId mismatch"
(ResponseError (RequestId requestId) msg) -> return $ Left msg (ResponseError (RequestId requestId) msg) -> return $ Left msg
_ -> return $ Left "Unknown error" _ -> return $ Left "Unknown error"
case result of
Just r -> pure $ r
_ -> pure $ Left "Request timeout"

Loading…
Cancel
Save