arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~

用于弹性异步代码的可组合构建块

Composable Building Blocks for Resilient Asynchronous Code

Frank Tip

arXiv 2608.21489首次发表:更新:

AI 中文总结

本文提出高阶组合子作为可组合构建块,统一解决异步代码的弹性问题,覆盖JavaScript两种原生异步形态,可用于增强实际包的弹性或并发控制。

AI 中文摘要

对网络服务、数据库或语言模型的异步调用必须应对瞬时错误、缓慢或缺失的响应、速率限制以及原子性违规问题。本文展示了高阶组合子如何统一解决此类问题,包括超时、重试、速率限制、缓存、可重入锁和取消操作。每个组合子都将一个异步函数映射为同类型的另一个函数,因此它们具有统一的“形态”,可通过嵌套组合成一个表达式,实现程序的整体弹性和并发策略,同时不触及业务逻辑。该设计覆盖了JavaScript的两种原生异步形态:返回Promise的函数和返回异步迭代器的函数,使用统一的关注点词汇。现有解决方案分散在形态各异的库中,难以组合。本文通过案例研究展示了如何使用这些组合子增强实际包的弹性或并发控制,替换定制策略。

英文摘要

Asynchronous calls to a network service, database, or language model must cope with transient errors, slow or missing responses, throttling, and atomicity violations. We show how higher-order combinators solve such problems uniformly, including timeouts, retries, rate limiting, caching, reentrant locking, and cancellation. Every combinator maps an async function to another of the same type, so they share a uniform \emph{shape} and compose by nesting into one expression that implements a program's whole resilience and concurrency policy, leaving its business logic untouched. The same design spans both of JavaScript's native async shapes, promise-returning and async-iterable-returning functions, with one vocabulary of concerns. Solutions exist across the ecosystem but are scattered over differently shaped libraries that are hard to combine. We present case studies where the combinators are used to harden real packages by adding missing resilience or concurrency control and replacing bespoke policy.

论文原文

arXiv 摘要页 · PDF 原文 · HTML 原文

↑