Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not withhold emission in pauseWhen #2813

Merged
merged 2 commits into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2196,12 +2196,16 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
def waitToResume =
pauseWhenTrue.discrete.dropWhile(_ == true).take(1).compile.drain

// The logic can be expressed entirely with `waitToResume`, but
// `Signal.get` is lighter than `Signal.discrete`, so the preliminary
// check with `get` in `pauseIfNeeded` acts as an optimisation, since
// we expect a stream to generally not be in a paused state.
def pauseIfNeeded = Stream.exec {
pauseWhenTrue.get.flatMap(paused => waitToResume.whenA(paused))
}

pauseIfNeeded ++ chunks.flatMap { chunk =>
pauseIfNeeded ++ Stream.chunk(chunk)
Stream.chunk(chunk) ++ pauseIfNeeded
}
}

Expand Down