@@ -399,7 +399,7 @@ processWithToken q heap st sv winfo action sno = do
399399 -- XXX deduplicate stop in all invocations
400400 let stop = do
401401 liftIO (incrementYieldLimit sv)
402− loopWithToken sno
402+ loopWithToken (sno + 1)
403403
404404 unStream action st stop (singleOutput sno) (yieldOutput sno)
405405
@@ -408,7 +408,7 @@ processWithToken q heap st sv winfo action sno = do
408408 singleOutput seqNo a = do
409409 continue <- liftIO $ sendYield sv winfo (ChildYield a)
410410 if continue
411− then loopWithToken seqNo
411+ then loopWithToken (seqNo + 1)
412412 else do
413413 liftIO $ updateHeapSeq heap (seqNo + 1)
414414 drainHeap q heap st sv winfo
@@ -423,7 +423,7 @@ processWithToken q heap st sv winfo action sno = do
423423 then do
424424 let stop = do
425425 liftIO (incrementYieldLimit sv)
426− loopWithToken seqNo
426+ loopWithToken (seqNo + 1)
427427 unStream r st stop
428428 (singleOutput seqNo)
429429 (yieldOutput seqNo)
@@ -433,27 +433,27 @@ processWithToken q heap st sv winfo action sno = do
433433 liftIO $ incrementYieldLimit sv
434434 drainHeap q heap st sv winfo
435435
436− loopWithToken prevSeqNo = do
436+ loopWithToken nextSeqNo = do
437437 work <- dequeueAhead q
438438 case work of
439439 Nothing -> do
440− liftIO $ updateHeapSeq heap (prevSeqNo + 1)
440+ liftIO $ updateHeapSeq heap nextSeqNo
441441 workLoopAhead q heap st sv winfo
442442
443443 Just (m, seqNo) -> do
444444 yieldLimitOk <- liftIO $ decrementYieldLimit sv
445445 if yieldLimitOk
446446 then
447− if seqNo == prevSeqNo + 1
447+ if seqNo == nextSeqNo
448448 then do
449449 let stop = do
450450 liftIO (incrementYieldLimit sv)
451− loopWithToken seqNo
451+ loopWithToken (seqNo + 1)
452452 unStream m st stop
453453 (singleOutput seqNo)
454454 (yieldOutput seqNo)
455455 else do
456− liftIO $ updateHeapSeq heap (prevSeqNo + 1)
456+ liftIO $ updateHeapSeq heap nextSeqNo
457457 liftIO (incrementYieldLimit sv)
458458 -- To avoid a race when another thread puts something
459459 -- on the heap and goes away, the consumer will not get
@@ -465,7 +465,7 @@ processWithToken q heap st sv winfo action sno = do
465465 liftIO $ reEnqueueAhead sv q m
466466 workLoopAhead q heap st sv winfo
467467 else do
468− liftIO $ updateHeapSeq heap (prevSeqNo + 1)
468+ liftIO $ updateHeapSeq heap nextSeqNo
469469 liftIO $ reEnqueueAhead sv q m
470470 liftIO $ incrementYieldLimit sv
471471 drainHeap q heap st sv winfo