@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 30 lines 970 Bytes
Raw
1 import * as Effect from "effect/Effect";
2 import * as Semaphore from "effect/Semaphore";
3
4 // The testing account has the default quota of five VPCs per Region. Its
5 // default VPC consumes one slot, and non-EC2 suites (EFS, ECS, RDS, etc.) may
6 // need another while EC2 tests run. Limit EC2 to three concurrent custom VPCs
7 // so the full AWS wave retains one spare slot instead of racing the hard quota.
8 const ec2VpcCapacity = Semaphore.makeUnsafe(3);
9
10 export const makeEc2VpcCapacityLease = (permits: 1 | 2 = 1) => {
11 let held = false;
12
13 return {
14 acquire: Effect.uninterruptibleMask((restore) =>
15 restore(ec2VpcCapacity.take(permits)).pipe(
16 Effect.tap(() =>
17 Effect.sync(() => {
18 held = true;
19 }),
20 ),
21 Effect.asVoid,
22 ),
23 ),
24 release: Effect.suspend(() => {
25 if (!held) return Effect.void;
26 held = false;
27 return ec2VpcCapacity.release(permits).pipe(Effect.asVoid);
28 }),
29 };
30 };