Skip to content

Commit baf1e32

Browse files
authored
Treat Creation of CountdownLatch With Negative Value as Die Failure (zio#7625)
* die * fix test
1 parent 78d5842 commit baf1e32

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

concurrent/shared/src/main/scala/zio/concurrent/CountdownLatch.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ final class CountdownLatch private (_count: Ref[Int], _waiters: Promise[Nothing,
4747
}
4848

4949
object CountdownLatch {
50-
def make(n: Int): IO[Option[Nothing], CountdownLatch] =
50+
def make(n: Int): UIO[CountdownLatch] =
5151
if (n <= 0)
52-
// People calling this with a negative value deserve this
53-
ZIO.none.flip
52+
ZIO.die(new IllegalArgumentException("n must be positive"))
5453
else
5554
Ref.make(n).zipWith(Promise.make[Nothing, Unit])(new CountdownLatch(_, _))
5655
}

concurrent/shared/src/test/scala/zio/concurrent/CountdownLatchSpec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ object CountdownLatchSpec extends ZIOSpecDefault {
1111
test("Creates a latch") {
1212
assertZIO(CountdownLatch.make(100).flatMap(_.count).exit)(succeeds(equalTo(100)))
1313
},
14-
test("Fails with an invalid count") {
15-
assertZIO(CountdownLatch.make(0).exit)(fails(equalTo(None)))
14+
test("Dies with an invalid count") {
15+
assertZIO(CountdownLatch.make(0).exit)(dies(anything))
1616
}
1717
),
1818
suite("Operations")(

0 commit comments

Comments
 (0)