@@ -287,9 +287,11 @@ callOpMsg pipe request flagBit params = do
287
287
(rt, r) ->
288
288
case r of
289
289
ReplyOpMsg {.. } ->
290
- if flagBits == [MoreToCome ]
291
- then yieldResponses .| foldlC mergeResponses p
292
- else return $ (rt, check reqId p)
290
+ if rt /= reqId then
291
+ error $ " expected response id (" ++ show rt ++ " ) to match request id (" ++ show reqId ++ " )"
292
+ else
293
+ if flagBits == [MoreToCome ] then yieldResponses .| foldlC mergeResponses p
294
+ else return (rt, r)
293
295
_ -> error " Impossible" -- see comment above
294
296
yieldResponses = repeatWhileMC
295
297
(do
@@ -298,27 +300,24 @@ callOpMsg pipe request flagBit params = do
298
300
readMVar var >>= either throwIO return :: IO Response
299
301
)
300
302
checkFlagBit
301
- mergeResponses p@ (rt,rep) p' =
302
- case (p, p') of
303
- ((_, r), (_, r')) ->
304
- case (r, r') of
305
- (ReplyOpMsg _ sec _, ReplyOpMsg _ sec' _) -> do
306
- let (section, section') = (head sec, head sec')
307
- (cur, cur') = (maybe Nothing cast $ look " cursor" section,
308
- maybe Nothing cast $ look " cursor" section')
309
- case (cur, cur') of
310
- (Just doc, Just doc') -> do
311
- let (docs, docs') =
312
- ( fromJust $ cast $ valueAt " nextBatch" doc :: [Document ]
313
- , fromJust $ cast $ valueAt " nextBatch" doc' :: [Document ])
314
- id' = fromJust $ cast $ valueAt " id" doc' :: Int32
315
- (rt, check id' (rt, rep{ sections = docs' ++ docs })) -- todo: avoid (++)
316
- -- Since we use this to process moreToCome messages, we
317
- -- know that there will be a nextBatch key in the document
318
- _ -> error " Impossible"
319
- _ -> error " Impossible" -- see comment above
320
- check requestId (responseTo, reply) = if requestId == responseTo then reply else
321
- error $ " expected response id (" ++ show responseTo ++ " ) to match request id (" ++ show requestId ++ " )"
303
+ mergeResponses (rt, rep) (_, rep') =
304
+ case (rep, rep') of
305
+ (ReplyOpMsg _ sec _, ReplyOpMsg _ sec' _) -> do
306
+ let (section, section') = (head sec, head sec')
307
+ (cur, cur') = ( cast =<< look " cursor" section
308
+ , cast =<< look " cursor" section'
309
+ )
310
+ case (cur, cur') of
311
+ (Just doc, Just doc') -> do
312
+ let (docs, docs') =
313
+ ( fromJust $ cast $ valueAt " nextBatch" doc :: [Document ]
314
+ , fromJust $ cast $ valueAt " nextBatch" doc' :: [Document ]
315
+ )
316
+ (rt, rep{ sections = docs' ++ docs }) -- todo: avoid (++)
317
+ -- Since we use this to process moreToCome messages, we
318
+ -- know that there will be a nextBatch key in the document
319
+ _ -> error " Impossible"
320
+ _ -> error " Impossible" -- see comment above
322
321
323
322
-- * Message
324
323
0 commit comments