From 73746f9b8d96ecd2b5503c37013a5fa1d17cb9d2 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 19 Aug 2024 19:56:02 +0200 Subject: [PATCH] Workaround for spread arguments --- shared/src/main/scala/async/Async.scala | 7 +++++-- shared/src/test/scala/ChannelBehavior.scala | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/shared/src/main/scala/async/Async.scala b/shared/src/main/scala/async/Async.scala index 3135e31d..6c0b7cb1 100644 --- a/shared/src/main/scala/async/Async.scala +++ b/shared/src/main/scala/async/Async.scala @@ -278,7 +278,10 @@ object Async: * @see * [[Async$.select Async.select]] for a convenient syntax to race sources and awaiting them with [[Async]]. */ - def race[T](@caps.unbox sources: (Source[T]^)*): Source[T]^{sources*} = raceImpl((v: T, _: SourceSymbol[T]) => v)(sources) + def race[T](@caps.unbox sources: Seq[Source[T]^]): Source[T]^{sources*} = raceImpl((v: T, _: SourceSymbol[T]) => v)(sources) + def race[T](s1: Source[T]^): Source[T]^{s1} = race(Seq(s1)) + def race[T](s1: Source[T]^, s2: Source[T]^): Source[T]^{s1, s2} = race(Seq(s1, s2)) + def race[T](s1: Source[T]^, s2: Source[T]^, s3: Source[T]^): Source[T]^{s1, s2, s3} = race(Seq(s1, s2, s3)) /** Like [[race]], but the returned value includes a reference to the upstream source that the item came from. * @see @@ -428,6 +431,6 @@ object Async: def either[T1, T2](src1: Source[T1]^, src2: Source[T2]^): Source[Either[T1, T2]]^{src1, src2} = val left = src1.transformValuesWith(Left(_)) val right = src2.transformValuesWith(Right(_)) - race(Seq(left, right)*) + race(left, right) end Async diff --git a/shared/src/test/scala/ChannelBehavior.scala b/shared/src/test/scala/ChannelBehavior.scala index 49c60e5b..67e9146e 100644 --- a/shared/src/test/scala/ChannelBehavior.scala +++ b/shared/src/test/scala/ChannelBehavior.scala @@ -255,8 +255,8 @@ class ChannelBehavior extends munit.FunSuite { } val race = Async.race( (0 until 100).map(i => - Async.race((10 * i until 10 * i + 10).map(idx => channels(idx).readSource.transformValuesWith(_.right.get))*) - )* + Async.race((10 * i until 10 * i + 10).map(idx => channels(idx).readSource.transformValuesWith(_.right.get))) + ) ) var sum = 0 for i <- 0 until 1000 do sum += race.awaitResult @@ -282,7 +282,7 @@ class ChannelBehavior extends munit.FunSuite { val ch = SyncChannel[Int]() var timesSent = 0 val race = Async.race( - (for i <- 0 until 1000 yield ch.sendSource(i))* + (for i <- 0 until 1000 yield ch.sendSource(i)) ) Future { while race.awaitResult.isRight do {