The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { HttpError } from './errors.ts'; |
| 2 | |
| 3 | // Isolate-wide resource counters contain no request data or I/O promises. Rate |
| 4 | // limiting controls traffic; these counters additionally bound simultaneous buffers. |
| 5 | export class Admission { |
| 6 | private stores = 0; |
| 7 | private reads = 0; |
| 8 | acquire(store: boolean): () => void { |
| 9 | if (store ? this.stores >= 2 : this.reads >= 4) throw new HttpError(503, 'concurrency_limit'); |
| 10 | if (store) this.stores++; |
| 11 | else this.reads++; |
| 12 | return () => { |
| 13 | if (store) this.stores--; |
| 14 | else this.reads--; |
| 15 | }; |
| 16 | } |
| 17 | } |