t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Railway/waitUntilVolumeGone.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

37 lines
1.2 KiB
TypeScript

import { Query } from "@distilled.cloud/core/query";
import { Railway } from "@distilled.cloud/railway";
import * as Effect from "effect/Effect";
import * as Schedule from "effect/Schedule";
const isGoneInstance = (instance: {
deletedAt: string | null;
isPendingDeletion: boolean;
state: string | null;
}) =>
instance.deletedAt != null ||
instance.isPendingDeletion ||
instance.state === "DELETED" ||
instance.state === "DELETING";
const readVolumeInstance = Query.fn((id: string) => {
const instance = Railway.volumeInstance({ id });
return {
deletedAt: instance.deletedAt,
isPendingDeletion: instance.isPendingDeletion,
state: instance.state,
};
});
/** Poll `volumeInstance({id})` until Railway reports the instance gone. */
export const waitUntilVolumeGone = (volumeInstanceId: string) =>
readVolumeInstance(volumeInstanceId).pipe(
Effect.map((instance) =>
isGoneInstance(instance) ? ("gone" as const) : ("found" as const),
),
Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
Effect.repeat({
schedule: Schedule.spaced("1 second"),
until: (status) => status === "gone",
times: 10,
}),
);