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.

714 B
Raw Blame
import type { MiddlewareHandler } from 'hono'

export class PushRequestDrain {
  private draining = false
  private active = 0
  private readonly waiters = new Set<() => void>()

  readonly middleware: MiddlewareHandler = async (context, next) => {
    if (this.draining) return context.json({ error: 'shutting_down' }, 503)
    this.active++
    try {
      await next()
    } finally {
      this.active--
      if (this.active === 0) {
        for (const resolve of this.waiters) resolve()
        this.waiters.clear()
      }
    }
  }

  begin(): Promise<void> {
    this.draining = true
    return this.active === 0
      ? Promise.resolve()
      : new Promise((resolve) => this.waiters.add(resolve))
  }
}