summaryrefslogtreecommitdiff
path: root/core/src/main/scala/mill/define/Worker.scala
blob: 0a6d31d2284b7460ddd8872acd308f19c94e2d61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package mill.define

import mill.util.Ctx

/**
  * Worker serves three purposes:
  *
  * - Cache in-memory state between tasks (e.g. object initialization)
  *   - Including warm classloaders with isolated bytecode
  * - Mutex to limit concurrency
  * - Manage out-of-process subprocesses <-- skip this for now
  *
  * Key usage:
  *
  * - T{
  *     ZincWorker().compile(a() + b())
  *   }
  *
  * Desugars into:
  *
  * - T.zipMap(ZincWorker, a, b){ (z, a1, b1) => z.compile(a1, b1) }
  *
  * Workers are shoehorned into the `Task` type. This lets them fit nicely in
  * the `T{...}` syntax, as well as being statically-inspectable before
  * evaluating the task graph. The Worker defines how it is evaluated, but it's
  * evaluation/caching/lifecycle are controlled by the `Evaluator`
  */
trait Worker[V] extends Task[V] with Ctx.Loader[V]{
  val inputs = Nil
  def make(): V
  def evaluate(args: Ctx) = args.load(this)
  def path = this.getClass.getCanonicalName.filter(_ != '$').split('.')
}