Files
geo/apps/desktop-client/src/main/runtime-events.ts
T

40 lines
945 B
TypeScript
Raw Normal View History

type RuntimeInvalidationReason = 'account-health' | 'publish-task-lease'
type RuntimeInvalidationListener = (event: {
reason: RuntimeInvalidationReason
at: number
accountId?: string
taskId?: string
}) => void
const listeners = new Set<RuntimeInvalidationListener>()
export function emitRuntimeInvalidated(
reason: RuntimeInvalidationReason,
details: { accountId?: string; taskId?: string } = {},
): void {
const event = {
reason,
at: Date.now(),
...details,
} as const
for (const listener of listeners) {
try {
listener(event)
} catch (error) {
console.warn('[desktop-runtime] invalidation listener failed', {
reason,
message: error instanceof Error ? error.message : String(error),
})
}
}
}
export function onRuntimeInvalidated(listener: RuntimeInvalidationListener): () => void {
listeners.add(listener)
return () => {
listeners.delete(listener)
}
}