The task type

In order to store state between tasks, we recommend following this convention:

type Task struct {
	*protocol.Task[Params]

	customState1 string
	customState2 int
	...
}

func ConstructTask(base *protocol.Task[Params]) (protocol.BaseTask, []flowprotocol.TaskStep, error) {
	t := &Task{
		Task: base,

		...
	}

	return t,
		[]flowprotocol.TaskStep{
			{step: t.SomeStep},
			...
		},
		nil
}

This allows for the state values to be accessed within the step functions or any other "Task" method.

It also allows for easy overriding of any BaseTask method by simply defining a new method on the Task type

Last updated