使任何 TypeScript 函数持久化
Make Any TypeScript Function Durable

原始链接: https://useworkflow.dev/

```typescript export async function welcome(userId: string) { "use workflow"; const user = await getUser(userId); const { subject, body } = await generateEmail({ name: user.name, plan: user.plan }); const { status } = await sendEmail({ to: user.email, subject, body, }); return { status, subject, body }; } ``` 导出异步函数 welcome(userId: string) { "use workflow"; const user = await getUser(userId); const { subject, body } = await generateEmail({ name: user.name, plan: user.plan }); const { status } = await sendEmail({ to: user.email, subject, body, }); return { status, subject, body }; }

## Vercel 的 “use workflow” – 具有容错机制的函数 Vercel 推出了一套名为 “workflow” 的新系统,旨在使 TypeScript 函数具有持久性,从而实现自动重试和确定性执行等功能。这是通过一种新颖但备受争议的语法实现的,该语法在函数定义中使用 “use workflow” 等指令。 这一发布引发了争论,许多开发者批评这种“魔术字符串”方法不够优雅,并且可能阻碍调试和工具支持。人们担心会像他们的 “use client” 和 “use server” 指令一样,被锁定在 Vercel 生态系统中。虽然 Vercel 声称该系统可以通过 “World” 接口进行调整,以允许使用不同的数据存储,但初始实现很大程度上依赖于 Next.js 和 DynamoDB。 讨论还涉及装饰器、高阶函数以及 Temporal 和 Cloudflare Workflows 等现有解决方案等替代方案。有些人将其与状态机概念相提并论,而另一些人则质疑增加复杂性的必要性,提倡更简单、更明确的方法。该项目被认为是早期阶段,关于状态管理、更新和配置等方面仍存在疑问。
相关文章

原文
export async function welcome(userId: string) {
  "use workflow";
  
  const user = await getUser(userId);
  const { subject, body } = await generateEmail({
    name: user.name, plan: user.plan
  });
  
  const { status } = await sendEmail({
    to: user.email,
    subject,
    body,
  });
  
  return { status, subject, body };
}
联系我们 contact @ memedata.com