I attend the Parallel Programming class and it shows a parallel interface:
def parallel[A, B](taskA: => A, taskB: => B): (A, B) = {
val ta = taskA
val tb = task {taskB}
(ta, tb.join())
}
and the following is not true:
def parallel[A, B](taskA: => A, taskB: => B): (A, B) = {
val ta = taskB
val tb = task {taskB}.join()
(ta, tb)
}
see interface more https://gist.github.com/ChenZhongPu/fe389d30626626294306264a148bd2aa
He also shows us the correct way to complete four tasks:
def parallel[A, B, C, D](taskA: => A, taskB: => B, taskC: => C, taskD: => D): (A, B, C, D) = {
val ta = task { taskA }
val tb = task { taskB }
val tc = task { taskC }
val td = taskD
(ta.join(), tb.join(), tc.join(), td)
}
My question is: if I do not know the number of tasks (task list), how can I correctly call joinfor each task?
tasks.map(_.join())
Edit
A similar discussion also takes place in the Discuss this week module: Parallel Programming