Files
orca/cloud/apps/relay/src/assignment-identity-queue.ts
T
Jinwoo Hong 3eec77c11a chore(cloud): add the relay fence broker, ops console, Terraform root, scripts, and 24 cloud-* workflows (#18413)
Phase 6 of the relay split: the relay's deploy/operate surface moves under cloud/ with 24 cloud-* workflows gated on ORCA_CLOUD_OPERATIONS_ENABLED, the Cloud SQL rollout lease action, the relay Terraform root (dual-accept identities for both repositories), scripts, docs, CODEOWNERS, and a terraform validate job in Cloud Verify.
2026-09-03 06:55:14 -04:00

25 lines
704 B
TypeScript

export type AssignmentIdentity = {
userId: string
relayHostId: string
}
export class AssignmentIdentityQueue {
private readonly tails = new Map<string, Promise<void>>()
async run<T>(identity: AssignmentIdentity, operation: () => Promise<T>): Promise<T> {
const key = JSON.stringify([identity.userId, identity.relayHostId])
const previous = this.tails.get(key) ?? Promise.resolve()
const result = previous.catch(() => undefined).then(operation)
const tail = result.then(
() => undefined,
() => undefined
)
this.tails.set(key, tail)
try {
return await result
} finally {
if (this.tails.get(key) === tail) this.tails.delete(key)
}
}
}