flow

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSlot

type DataSlot struct {
	// contains filtered or unexported fields
}

DataSlot 数据槽 作用:存储一个值,支持多协程等待、多订阅、重复读取、广播唤醒 一个值生成后,所有节点都能获取

func NewDataSlot

func NewDataSlot() *DataSlot

func (*DataSlot) Done

func (s *DataSlot) Done() <-chan struct{}

Done 返回通知 channel,值被设置时会被 close

func (*DataSlot) Get

func (s *DataSlot) Get(ctx context.Context) (any, error)

Get 等待值就绪

func (*DataSlot) IsReady

func (s *DataSlot) IsReady() bool

IsReady 检查值是否已就绪

func (*DataSlot) Set

func (s *DataSlot) Set(value any)

Set 写入值(唤醒所有等待者) 行为同 SetOnce,保持向后兼容

func (*DataSlot) SetOnce

func (s *DataSlot) SetOnce(value any)

SetOnce 首次写入值(幂等:如果已设置则忽略,不报错) 适用于:节点输出写入上下文,确保只写入一次

func (*DataSlot) SetOrUpdate

func (s *DataSlot) SetOrUpdate(value any)

SetOrUpdate 写入或更新值(始终覆盖,唤醒等待者) 适用于:ReAct 重规划时更新计划、状态变更等场景 注意:更新时会再次 Broadcast,确保新等待者能获取最新值

func (*DataSlot) TryGet

func (s *DataSlot) TryGet() (any, bool)

TryGet 非阻塞获取值 返回值和 true 表示获取成功 返回 nil 和 false 表示值尚未就绪

type FlowContext

type FlowContext struct {
	// contains filtered or unexported fields
}

func NewFlowContext

func NewFlowContext(ctx context.Context) *FlowContext

func (*FlowContext) Cancel

func (c *FlowContext) Cancel(err error)

Cancel 取消工作流并记录首个错误

func (*FlowContext) Done

func (c *FlowContext) Done() <-chan struct{}

Done 返回取消信号 channel

func (*FlowContext) Err

func (c *FlowContext) Err() error

Err 返回工作流级错误

func (*FlowContext) Get

func (c *FlowContext) Get(key string) (any, error)

Get 等待数据就绪并返回

func (*FlowContext) GetContext

func (c *FlowContext) GetContext() context.Context

func (*FlowContext) GetError

func (c *FlowContext) GetError() error

GetError 获取已记录的首个错误(不触发取消)

func (*FlowContext) IsReady

func (c *FlowContext) IsReady(key string) bool

IsReady 检查是否已就绪

func (*FlowContext) Set

func (c *FlowContext) Set(key string, value any)

Set 放入数据(首次设置,已存在则忽略)

func (*FlowContext) SetError

func (c *FlowContext) SetError(err error) error

SetError 设置错误并触发取消

func (*FlowContext) SetOnce

func (c *FlowContext) SetOnce(key string, value any)

SetOnce 同 Set

func (*FlowContext) SetOrUpdate

func (c *FlowContext) SetOrUpdate(key string, value any)

SetOrUpdate 放入或更新数据(始终覆盖)

func (*FlowContext) TryGet

func (c *FlowContext) TryGet(key string) (any, bool)

TryGet 非阻塞获取

func (*FlowContext) Wait

func (c *FlowContext) Wait(key string) (any, error)

Wait 等待数据就绪

func (*FlowContext) WaitAll

func (c *FlowContext) WaitAll(keys ...string) (map[string]any, error)

WaitAll 等待多个数据全部就绪

func (*FlowContext) WaitAllWithContext

func (c *FlowContext) WaitAllWithContext(ctx context.Context, keys ...string) (map[string]any, error)

WaitAllWithContext 使用指定 context 等待多个数据全部就绪

func (*FlowContext) WaitForAny

func (c *FlowContext) WaitForAny(keys ...string) (string, any, error)

WaitForAny 等待多个 key 中任意一个就绪 基于 done channel + reflect.Select,零轮询

func (*FlowContext) WaitWithContext

func (c *FlowContext) WaitWithContext(ctx context.Context, key string) (any, error)

WaitWithContext 使用指定 context 等待数据就绪 用于切面级超时控制:传入切面的 context 而非工作流的 context

type SafeMap

type SafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SafeMap 泛型并发安全 Map K: 键类型(必须可比较) V: 值类型(任意)

func (*SafeMap[K, V]) Clear

func (s *SafeMap[K, V]) Clear()

Clear 清空所有数据

func (*SafeMap[K, V]) Delete

func (s *SafeMap[K, V]) Delete(key K)

Delete 删除值

func (*SafeMap[K, V]) Exist

func (s *SafeMap[K, V]) Exist(key K) bool

Exist 判断 key 是否存在

func (*SafeMap[K, V]) Get

func (s *SafeMap[K, V]) Get(key K) (V, bool)

Get 取值

func (*SafeMap[K, V]) GetOrSet

func (s *SafeMap[K, V]) GetOrSet(key K, createFn func() V) V

GetOrSet 原子的「获取或创建」 已存在则返回已有值,不存在则调用 createFn 创建后存入

func (*SafeMap[K, V]) MustGet

func (s *SafeMap[K, V]) MustGet(key K) V

MustGet 没有就panic

func (*SafeMap[K, V]) Range

func (s *SafeMap[K, V]) Range(fn func(key K, value V) bool)

Range 遍历所有键值对

func (*SafeMap[K, V]) Set

func (s *SafeMap[K, V]) Set(key K, value V)

Set 存值

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL