Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

704 B
Raw Blame
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)
    }
  }
}