Fix an issue of prolonged delay in the Delay stage #26470

This commit is contained in:
Xin Yin 2019-07-05 03:07:16 -04:00 committed by Johan Andrén
parent 51041b1faf
commit 44dcfe057a
2 changed files with 43 additions and 2 deletions

View file

@ -1747,7 +1747,7 @@ private[stream] object Collect {
case _: DropNew =>
() => {
grab(in)
if (!isTimerActive(timerName)) scheduleOnce(timerName, d)
pull(in)
}
case _: DropBuffer =>
() => {
@ -1770,7 +1770,13 @@ private[stream] object Collect {
else {
grabAndPull()
if (!isTimerActive(timerName)) {
scheduleOnce(timerName, d)
// schedule a timer for the full-delay `d` only if the buffer is empty, because otherwise a
// full-length timer will starve subsequent `onPull` callbacks, preventing overdue elements
// to be discharged.
if (buffer.isEmpty)
scheduleOnce(timerName, d)
else
scheduleOnce(timerName, Math.max(DelayPrecisionMS, nextElementWaitTime()).millis)
}
}
}