The application builds a short summary from incoming events and caches the result for repeated requests. In one scenario, the final string becomes stale or has an incorrect number of elements after the data source changes.
Scala 3.3.1 and JDK 21 are used.scala-cli test ..ExecutionContext is passed explicitly.SummaryService.summary(): Future[String]SummaryService.refresh(): UnitLazyList[String].refresh() the next call to summary() must take the current source state into account.summary() and wait for the string.refresh().summary() again.Example expected scenario:
val service = new SummaryService(() => LazyList("a", "b", "c"))(using ec)
val first = Await.result(service.summary(), 1.second)
service.refresh()
val second = Await.result(service.summary(), 1.second)
refresh(), a repeated call must not return a stale result.ExecutionContext must be passed explicitly and used via givenUse line comments to explain the problem, its impact, the fix and how to test it.