refactor: share timeout abort helper with matrix

This commit is contained in:
Peter Steinberger
2026-04-20 23:28:36 +01:00
parent 8b7418b127
commit 4fb2e2309e
2 changed files with 2 additions and 31 deletions

View File

@@ -1,31 +1 @@
export function buildTimeoutAbortSignal(params: { timeoutMs?: number; signal?: AbortSignal }): {
signal?: AbortSignal;
cleanup: () => void;
} {
const { timeoutMs, signal } = params;
if (!timeoutMs && !signal) {
return { signal: undefined, cleanup: () => {} };
}
if (!timeoutMs) {
return { signal, cleanup: () => {} };
}
const controller = new AbortController();
const timeoutId = setTimeout(controller.abort.bind(controller), timeoutMs);
const onAbort = () => controller.abort();
if (signal) {
if (signal.aborted) {
controller.abort();
} else {
signal.addEventListener("abort", onAbort, { once: true });
}
}
return {
signal: controller.signal,
cleanup: () => {
clearTimeout(timeoutId);
signal?.removeEventListener("abort", onAbort);
},
};
}
export { buildTimeoutAbortSignal } from "openclaw/plugin-sdk/extension-shared";

View File

@@ -3,6 +3,7 @@ import { hasEnvHttpProxyConfigured } from "../infra/net/proxy-env.js";
import { runPassiveAccountLifecycle } from "./channel-lifecycle.core.js";
import { createLoggerBackedRuntime } from "./runtime-logger.js";
export { safeParseJsonWithSchema, safeParseWithSchema } from "../utils/zod-parse.js";
export { buildTimeoutAbortSignal } from "../utils/fetch-timeout.js";
type PassiveChannelStatusSnapshot = {
configured?: boolean;