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

Add Channel#closeWithElement #3280

Merged
merged 19 commits into from
Sep 12, 2023
Merged
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/fs2/concurrent/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ object Channel {
State(values, size, None, (a, producer) :: producers, close),
signalClosure.whenA(close) *>
notifyStream(waiting).as(rightUnit) <*
waitOnBound(producer, poll)
waitOnBound(producer, poll).whenA(!close)
tothpeti marked this conversation as resolved.
Show resolved Hide resolved
tothpeti marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/test/scala/fs2/concurrent/ChannelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ class ChannelSuite extends Fs2Suite {
checkIfSendAndCloseClosing(channel).parReplicateA_(if (isJVM) 10000 else 1)
}

test("sendAndClose closes right after sending the last element in synchronous case") {
val channel = Channel.synchronous[IO, Int]

checkIfSendAndCloseClosing(channel).parReplicateA_(if (isJVM) 10000 else 1)
}

def racingSendOperations(channel: IO[Channel[IO, Int]]) = {
val expectedFirstCase = ((Right(()), Right(())), List(0, 1))
val expectedSecondCase = ((Right(()), Left(Channel.Closed)), List(1))
Expand Down