Skip to content

Commit

Permalink
fix(analyzer): await directly future results instead of await on Futu…
Browse files Browse the repository at this point in the history
…re of no results, updating concurrently (i.e with race conditions) the results
  • Loading branch information
tassiluca committed Mar 6, 2024
1 parent 63a5047 commit fbe14f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ private class IncrementalAnalyzer(repositoryService: RepositoryService) extends
updateResults: RepositoryReport => Unit,
)(using Async, AsyncOperations): Either[String, Seq[RepositoryReport]] = either:
val reposInfo = repositoryService.incrementalRepositoriesOf(organizationName)
var allReports = Seq[RepositoryReport]()
var futures = Seq[Future[Unit]]()
var futures = Seq[Future[RepositoryReport]]()
reposInfo.foreach { repository =>
futures = futures :+ Future:
val report = repository.?.performAnalysis.run.awaitResult.?
updateResults(report)
allReports = allReports :+ report
report
}
futures.awaitAllOrCancel
allReports
12 changes: 5 additions & 7 deletions docs/content/docs/03-channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,16 @@ Then, the implementation of the `analyze` method becomes:
```scala
override def analyze(organizationName: String)(
updateResults: RepositoryReport => Unit,
)(using Async): Either[String, Seq[RepositoryReport]] = either:
)(using Async, AsyncOperations): Either[String, Seq[RepositoryReport]] = either:
val reposInfo = repositoryService.incrementalRepositoriesOf(organizationName) // 1
var allReports = Seq[RepositoryReport]()
var futures = Seq[Future[Unit]]()
var futures = Seq[Future[RepositoryReport]]()
reposInfo.foreach { repository => // 2
futures = futures :+ Future: // 3
val report = repository.?.performAnalysis.awaitResult.?
val report = repository.?.performAnalysis.run.awaitResult.?
updateResults(report)
allReports = allReports :+ report
report
}
futures.awaitAllOrCancel // 4
allReports
futures.awaitAllOrCancel
```

1. we get the channel of repositories from the repository service;
Expand Down

0 comments on commit fbe14f0

Please sign in to comment.