Skip to content

Commit

Permalink
Iterate over promises in reverse order
Browse files Browse the repository at this point in the history
It is likely that the last promise completes last. If that is the case, we only wait once, the other promises are already completed and awaiting them has no overhead.
  • Loading branch information
erikvanoosten committed Aug 26, 2024
1 parent 7c2cf3d commit 0a12d29
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zio-kafka/src/main/scala/zio/kafka/producer/Producer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ private[producer] final class ProducerLive(
): ZIO[Any, Nothing, Chunk[Either[Throwable, RecordMetadata]]] =
for {
promises <- ZIO.foreach(serializedRecords)(sendRecord(runtime))
results <- ZIO.foreach(promises)(_.await.either)
} yield results
results <- ZIO.foreach(promises.reverse)(_.await.either)
} yield results.reverse

private def sendRecord(
runtime: Runtime[Any]
Expand Down

0 comments on commit 0a12d29

Please sign in to comment.