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).whenA(!close)
waitOnBound(producer, poll)
)
}
}
Expand Down
12 changes: 10 additions & 2 deletions core/shared/src/test/scala/fs2/concurrent/ChannelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,17 @@ class ChannelSuite extends Fs2Suite {
}

test("sendAndClose closes right after sending the last element in synchronous case") {
val channel = Channel.synchronous[IO, Int]
val test = Channel
.synchronous[IO, Int]
.flatMap { ch =>
ch.stream
.concurrently(Stream.emit(0).covary[IO].evalMap(ch.sendAndClose))
.compile
.drain *> ch.isClosed
}
.assertEquals(true)
tothpeti marked this conversation as resolved.
Show resolved Hide resolved

checkIfSendAndCloseClosing(channel).parReplicateA_(if (isJVM) 10000 else 1)
test.parReplicateA_(if (isJVM) 10000 else 1)
tothpeti marked this conversation as resolved.
Show resolved Hide resolved
}

def racingSendOperations(channel: IO[Channel[IO, Int]]) = {
Expand Down