Skip to content

Commit

Permalink
Workaround for spread arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
natsukagami committed Aug 19, 2024
1 parent 74cde6d commit 73746f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions shared/src/main/scala/async/Async.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

6 changes: 3 additions & 3 deletions shared/src/test/scala/ChannelBehavior.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 73746f9

Please sign in to comment.