






















@@ -87,6 +87,26 @@ function createCoordinator(onReplyStart?: (...args: unknown[]) => Promise<void>)
8787});
8888}
898990+async function raceWithTimeoutResult<T>(
91+promise: Promise<T>,
92+timeoutMs: number,
93+timeoutResult: T,
94+): Promise<T> {
95+let timer: ReturnType<typeof setTimeout> | undefined;
96+try {
97+return await Promise.race([
98+promise,
99+new Promise<T>((resolve) => {
100+timer = setTimeout(() => resolve(timeoutResult), timeoutMs);
101+}),
102+]);
103+} finally {
104+if (timer) {
105+clearTimeout(timer);
106+}
107+}
108+}
109+90110function createVisibleChatAcpCoordinator(cfg: OpenClawConfig) {
91111return createAcpDispatchDeliveryCoordinator({
92112 cfg,
@@ -356,12 +376,11 @@ describe("createAcpDispatchDeliveryCoordinator", () => {
356376);
357377const coordinator = createCoordinator(onReplyStart);
358378359-const delivered = await Promise.race([
379+const delivered = await raceWithTimeoutResult(
360380coordinator.deliver("final", { text: "hello" }).then(() => "delivered"),
361-new Promise<string>((resolve) => {
362-setTimeout(() => resolve("timed-out"), 50);
363-}),
364-]);
381+50,
382+"timed-out",
383+);
365384366385expect(delivered).toBe("delivered");
367386expect(onReplyStart).toHaveBeenCalledTimes(1);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。