跳转到内容

WorkflowEvent

工作流事件<Data, DebugLabel> = object & object

定义于:core/src/core/event.ts:65

表示一种工作流事件类型,可通过数据实例化。

事件是工作流的核心构建块。它们定义了流经系统的数据结构,并可用于触发处理器。

optional 调试标签: DebugLabel

用于调试和日志记录目的的可选标签。

readonly 唯一标识符: string

事件类型的唯一标识符,用于序列化和网络通信。

使用(data): WorkflowEventData<Data, DebugLabel>

使用提供的有效载荷创建事件数据。

Data

此事件实例的数据载荷

WorkflowEventData<Data, DebugLabel>

可通过工作流上下文发送的事件数据

include(event): event is WorkflowEventData<Data, DebugLabel>

类型守卫,用于检查未知事件数据是否属于此事件类型。

unknown

未知事件数据待检查

event is WorkflowEventData<Data, DebugLabel>

如果事件数据属于此事件类型则为真

onInit(callback): Cleanup

注册一个回调函数,当此事件类型被实例化时调用。

Callback

事件创建时调用的函数

Cleanup

用于移除回调的清理函数

readonly [不透明符号]: DebugLabel

Data

此事件可携带的数据类型

DebugLabel 扩展 string = string

用于开发/调试的可选调试标签

// Create an event type
const UserLoginEvent = workflowEvent<\{ userId: string; timestamp: Date \}>();
// Create event data
const loginData = UserLoginEvent.with(\{
userId: 'user123',
timestamp: new Date()
\});
// Check if data belongs to this event type
if (UserLoginEvent.include(someEventData)) \{
console.log('User ID:', someEventData.data.userId);
\}