mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
export type EnsureTiming = {
|
|
readonly pollInterval: number
|
|
readonly requestTimeout: number
|
|
readonly spawnDelay: number
|
|
readonly maxSpawnDelay: number
|
|
readonly promiseTimeout: number
|
|
readonly stopPollInterval: number
|
|
readonly stopPollAttempts: number
|
|
}
|
|
|
|
const timings = new WeakMap<object, EnsureTiming>()
|
|
|
|
// A freshly spawned service registers in ~250 ms, so the poll cadence is a large share of the
|
|
// time a client waits for it. Probes are sequential, so the wait between them only matters while
|
|
// the connection is refused; both variants give up after promiseTimeout of wall-clock time.
|
|
export const defaultEnsureTiming: EnsureTiming = {
|
|
pollInterval: 25,
|
|
requestTimeout: 2_000,
|
|
spawnDelay: 5_000,
|
|
maxSpawnDelay: 30_000,
|
|
promiseTimeout: 120_000,
|
|
stopPollInterval: 50,
|
|
stopPollAttempts: 100,
|
|
}
|
|
|
|
export function ensureTiming(options: object) {
|
|
return timings.get(options) ?? defaultEnsureTiming
|
|
}
|
|
|
|
// Keep test timing out of the public lifecycle option types.
|
|
export function withEnsureTiming<A extends object>(options: A, overrides: Partial<EnsureTiming>): A {
|
|
timings.set(options, { ...defaultEnsureTiming, ...overrides })
|
|
return options
|
|
}
|