-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.go
More file actions
38 lines (31 loc) · 1.51 KB
/
action.go
File metadata and controls
38 lines (31 loc) · 1.51 KB
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
34
35
36
37
38
package chain
import (
"context"
)
// Action is the basic unit of execution in a package.
// It represents a single task that processes input and produces output.
type Action[T any] interface {
// Name provides the identifier of this Action.
Name() string
// Run executes the Action, processing the input and returning output or an error.
Run(ctx context.Context, input T) (output T, err error)
}
// BranchAction is an interface for actions that control branching in the execution flow
// of a Workflow. It extends the Action interface and adds methods for handling conditional
// branching based on the execution results.
type BranchAction[T any] interface {
// Name returns the name of the BranchAction.
Name() string
// Run executes the branch action, optionally modifying the input and returning an output.
// If the input doesn't need changes, it can be passed through as output. The method also
// returns an error if the action cannot be executed successfully.
Run(ctx context.Context, input T) (output T, err error)
// Directions return a list of possible directions that the Workflow can take.
// These directions are used for validation and must include all possible values that
// NextDirection can return.
Directions() []string
// NextDirection determines the next execution path based on the result of Run.
// It is called only if Run succeeds (err == nil).
// The method returns a direction from the list defined by Directions.
NextDirection(ctx context.Context, output T) (direction string, err error)
}