SwitchTask

interface SwitchTask : Task

A task that chooses one of several tasks to run; every other one is skipped.

Register one with DagDef.Switch, then list what it can choose with SwitchRef.Case. The choice is the class of the task to run:

public class PickPath implements SwitchTask {
@Override
public Class<? extends Task> choose(Context context, Client client) {
return ((Number) client.getXCom("extract")).longValue() > 1000
? HandleLong.class
: HandleShort.class;
}
}

The SDK runs choose and pushes the chosen task's ID as this task's return value, so execute is never called.

Only a Task class compiles as a choice. javac cannot tell whether it is a case of this switch, so a Task class that is not one compiles and fails when the task runs: the task instance is marked failed, and nothing is pushed or skipped.

Because a switch names a case by its class, two tasks that run the same class cannot both be cases of it; the second SwitchRef.Case call throws.

See also

Functions

Link copied to clipboard
abstract fun choose(context: Context, client: Client): Class<out Task>

Chooses the one case that runs.

Link copied to clipboard
open override fun execute(context: Context, client: Client)

Never called: the SDK runs a switch through choose.