I have use case to implement in scala 2. When the application starts, a I have a list of Tasks to execute 3 at a time. However at the end of each executed Task/Future, I need to rebuild the list of Tasks and feed my thread pool with it again.
implicit val executionContext: ExecutionContextExecutorService = ExecutionContext
.fromExecutorService(Executors.newFixedThreadPool(3))
var tasks: List[Int] = getCurrentTasks()
val filterFutures: List[Future[Boolean]] = for ((task, idx) <- tasks.zipWithIndex)
yield Future[Int] {
// Based on task (ID integer), some long running jobs are executed here
tasks = getCurrentTasks() // update list of tasks
true
}
def getCurrentTasks(): List[Int] = {
// dynamically fetching from DB
}