Documentation
¶
Index ¶
- Variables
- type DataSlot
- type FlowContext
- func (c *FlowContext) Cancel(err error)
- func (c *FlowContext) Done() <-chan struct{}
- func (c *FlowContext) Err() error
- func (c *FlowContext) Get(key string) (any, error)
- func (c *FlowContext) GetContext() *context.Context
- func (c *FlowContext) GetError() error
- func (c *FlowContext) IsReady(key string) bool
- func (c *FlowContext) Set(key string, value any)
- func (c *FlowContext) SetError(err error) error
- func (c *FlowContext) SetOnce(key string, value any)
- func (c *FlowContext) SetOrUpdate(key string, value any)
- func (c *FlowContext) TryGet(key string) (any, bool)
- func (c *FlowContext) Wait(key string) (any, error)
- func (c *FlowContext) WaitAll(keys ...string) (map[string]any, error)
- func (c *FlowContext) WaitForAny(keys ...string) (string, any, error)
- type LoopResult
- func NewLoopCancelledResult(iterations int, err error) *LoopResult
- func NewLoopCompletedResult(iterations int) *LoopResult
- func NewLoopMaxIterationsResult(maxIterations, actualIterations int) *LoopResult
- func NewLoopResult(status LoopStatus, iterations int, message string) *LoopResult
- func NewLoopTimeoutResult(iterations int) *LoopResult
- type LoopStatus
- type SafeMap
- func (s *SafeMap[K, V]) Clear()
- func (s *SafeMap[K, V]) Delete(key K)
- func (s *SafeMap[K, V]) Exist(key K) bool
- func (s *SafeMap[K, V]) Get(key K) (V, bool)
- func (s *SafeMap[K, V]) GetOrSet(key K, createFn func() V) V
- func (s *SafeMap[K, V]) MustGet(key K) V
- func (s *SafeMap[K, V]) Range(fn func(key K, value V) bool)
- func (s *SafeMap[K, V]) Set(key K, value V)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrWorkflowRunning = errors.New("workflow is already running") ErrWorkflowResetRunning = errors.New("cannot reset a running workflow") ErrWorkflowSubmitNodeToPool = errors.New("failed to submit node to pool") ErrWorkflowClosed = errors.New("workflow has been closed and cannot be used") )
View Source
var ( ErrLoopCancelled = errors.New("loop cancelled") ErrLoopTimeout = errors.New("loop timeout") )
Loop 相关的错误
Functions ¶
This section is empty.
Types ¶
type DataSlot ¶
type DataSlot struct {
// contains filtered or unexported fields
}
DataSlot 数据槽 作用:存储一个值,支持多协程等待、多订阅、重复读取、广播唤醒 一个值生成后,所有节点都能获取
func NewDataSlot ¶
func NewDataSlot() *DataSlot
func (*DataSlot) SetOrUpdate ¶
SetOrUpdate 写入或更新值(始终覆盖,唤醒等待者) 适用于:ReAct 重规划时更新计划、状态变更等场景 注意:更新时会再次 Broadcast,确保新等待者能获取最新值
type FlowContext ¶
type FlowContext struct {
// contains filtered or unexported fields
}
func NewFlowContext ¶
func NewFlowContext(ctx context.Context) *FlowContext
func (*FlowContext) GetContext ¶
func (c *FlowContext) GetContext() *context.Context
func (*FlowContext) SetOrUpdate ¶
func (c *FlowContext) SetOrUpdate(key string, value any)
SetOrUpdate 放入或更新数据(始终覆盖)
func (*FlowContext) WaitAll ¶
func (c *FlowContext) WaitAll(keys ...string) (map[string]any, error)
WaitAll 等待多个数据全部就绪
func (*FlowContext) WaitForAny ¶
func (c *FlowContext) WaitForAny(keys ...string) (string, any, error)
WaitForAny 等待多个 key 中任意一个就绪 基于 done channel + reflect.Select,零轮询
type LoopResult ¶
type LoopResult struct {
Status LoopStatus `json:"status"` // 结束状态
Iterations int `json:"iterations"` // 实际执行次数
Message string `json:"message"` // 详细描述
}
LoopResult 循环执行结果
func NewLoopCancelledResult ¶
func NewLoopCancelledResult(iterations int, err error) *LoopResult
NewLoopCancelledResult 创建被取消的循环结果
func NewLoopCompletedResult ¶
func NewLoopCompletedResult(iterations int) *LoopResult
NewLoopCompletedResult 创建正常完成的循环结果
func NewLoopMaxIterationsResult ¶
func NewLoopMaxIterationsResult(maxIterations, actualIterations int) *LoopResult
NewLoopMaxIterationsResult 创建达到最大次数的循环结果
func NewLoopResult ¶
func NewLoopResult(status LoopStatus, iterations int, message string) *LoopResult
NewLoopResult 创建循环结果
func NewLoopTimeoutResult ¶
func NewLoopTimeoutResult(iterations int) *LoopResult
NewLoopTimeoutResult 创建超时的循环结果
func (*LoopResult) ToMap ¶
func (r *LoopResult) ToMap() map[string]any
ToMap 转换为 map,方便放入 FlowContext
type LoopStatus ¶
type LoopStatus string
LoopStatus 循环执行状态
const ( LoopStatusCompleted LoopStatus = "completed" // 正常完成 LoopStatusMaxIterations LoopStatus = "max_iterations" // 达到最大循环次数 LoopStatusTimeout LoopStatus = "timeout" // 超时 LoopStatusCancelled LoopStatus = "cancelled" // 被取消 LoopStatusConditionFailed LoopStatus = "condition_failed" // 条件不满足 )
type SafeMap ¶
type SafeMap[K comparable, V any] struct { // contains filtered or unexported fields }
SafeMap 泛型并发安全 Map K: 键类型(必须可比较) V: 值类型(任意)
func (*SafeMap[K, V]) GetOrSet ¶
func (s *SafeMap[K, V]) GetOrSet(key K, createFn func() V) V
GetOrSet 原子的「获取或创建」 已存在则返回已有值,不存在则调用 createFn 创建后存入
Click to show internal directories.
Click to hide internal directories.