t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/EC2/VpcCapacity.ts
Julius Marminge 108e01746c
Upgrade Effect and Alchemy betas (#4643)
Prepare Relay production infrastructure for the PlanetScale PS_20 HA topology, upgrade Effect and Alchemy to compatible betas, reconcile migration state, and preserve patched MCP session termination behavior.\n\nCo-authored-by: codex <codex@users.noreply.github.com>
2026-07-27 16:21:02 +02:00

30 lines
970 B
TypeScript

import * as Effect from "effect/Effect";
import * as Semaphore from "effect/Semaphore";
// The testing account has the default quota of five VPCs per Region. Its
// default VPC consumes one slot, and non-EC2 suites (EFS, ECS, RDS, etc.) may
// need another while EC2 tests run. Limit EC2 to three concurrent custom VPCs
// so the full AWS wave retains one spare slot instead of racing the hard quota.
const ec2VpcCapacity = Semaphore.makeUnsafe(3);
export const makeEc2VpcCapacityLease = (permits: 1 | 2 = 1) => {
let held = false;
return {
acquire: Effect.uninterruptibleMask((restore) =>
restore(ec2VpcCapacity.take(permits)).pipe(
Effect.tap(() =>
Effect.sync(() => {
held = true;
}),
),
Effect.asVoid,
),
),
release: Effect.suspend(() => {
if (!held) return Effect.void;
held = false;
return ec2VpcCapacity.release(permits).pipe(Effect.asVoid);
}),
};
};