KScript docs
EN

chain fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

From KScript.Queue

These need <import package="KScript.Queue" />import KScript.Queue. See KScript.Queue.

#chain->count() → number KScript.Queue

How many jobs are in the chain.
Example
<job name="Step" fields="n: int">
  <fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<echo>{ @chain([Step(n: 1), Step(n: 2)])->count() }</echo>
job Step {
  n: int
  fn handle() {
    echo "Step { .n }"
  }
}
echo @chain([Step(n: 1), Step(n: 2)])->count()

#chain->dispatch(delay?: duration, at?: date, queue?: string(min: 1), connection?: string(min: 1), after_commit?: bool) → map KScript.Queue

Queues the first job of the chain; each of the others is queued when the one before it succeeds. Inside a transaction it waits for the commit, as a job does.
ParameterTakes
delay optionalduration
at optionaldate
queue optionalstring(min: 1)
connection optionalstring(min: 1)
after_commit optionala flag: after_commit or not after_commit

Arguments can be named: ->dispatch(…, at: …, queue: …).

Example
<job name="Step" fields="n: int">
  <fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<do>@fake_queue()</do>
<do>@chain([Step(n: 1), Step(n: 2)])->dispatch()</do>
job Step {
  n: int
  fn handle() {
    echo "Step { .n }"
  }
}
@fake_queue()
@chain([Step(n: 1), Step(n: 2)])->dispatch()

#chain->run() KScript.Queue

Runs the jobs now, here, one after another.
Example
<job name="Step" fields="n: int">
  <fn name="handle"><echo>Step { $n }</echo></fn>
</job>
<do>@chain([Step(n: 1), Step(n: 2)])->run()</do>
job Step {
  n: int
  fn handle() {
    echo "Step { .n }"
  }
}
@chain([Step(n: 1), Step(n: 2)])->run()

Methods from any