Scala wait Await.result for Future.sequence, which futures did not complete on time?

42 Views Asked by At

I have list of futures and Await

val listWithResult = Await.result(Future.sequence(listOfFutures), 10.minutes)

It fails with

java.util.concurrent.TimeoutException: Futures timed out after [10 minutes]
  • Is there any technique to figure out which future did not complete on time?
  • Its there any way to attribute such future with extra metadata to give a clue why it did not complete on time?

Each future submits task and polls polls external service for result. I would like to show that task in stacktrace somehow.

1

There are 1 best solutions below

1
Dima On

Well, you can figure out what didn't complete fairly easily with something like listOfFutures.filterNot(_.isCompleted).

(also, keep in mind, that Await is code smell and in vast majority of cases, really not what you want to do).

As to "why", I don't think there is any universal advice here, aside for the usual: logging, metrics, tracing ..