sbt/tasks/TaskRunner.scala

21 lines
985 B
Scala
Raw Normal View History

2009-08-16 20:29:08 +02:00
package xsbt
object TaskRunner
{
def apply[T](node: Task[T]): T = apply(node, Runtime.getRuntime.availableProcessors)
2009-08-16 20:29:08 +02:00
/** Executes work for nodes in a directed acyclic graph with root node `node`.
* The maximum number of tasks to execute simultaneously is `maximumTasks`. */
def apply[T](node: Task[T], maximumTasks: Int): T =
2009-08-16 20:29:08 +02:00
{
require(maximumTasks > 0)
2009-12-12 00:56:09 +01:00
val compute = new Compute[Work, Result] { def apply[A](w: Work[A]) = w.apply }
val strategy = new SimpleStrategy[Work[_]]
2009-08-16 20:29:08 +02:00
val scheduler = new TaskScheduler(node, strategy, new BasicTaskListener)
2009-12-12 00:56:09 +01:00
val distributor = new Distributor[ Either[ List[WorkFailure[Task[_]]], T ] , Work, Result](scheduler, compute, maximumTasks)
distributor.run().fold(failures => throw new TasksFailed(failures), identity[T])
2009-08-16 20:29:08 +02:00
}
}
2009-08-31 03:45:49 +02:00
final case class TasksFailed(failures: List[WorkFailure[Task[_]]]) extends RuntimeException(failures.length + " tasks failed")
{
override def toString = failures.mkString(getMessage + "\n", "\n\t", "\n")
}