1import * as Fly from "@/Fly";
2import * as Cause from "effect/Cause";
3import * as Effect from "effect/Effect";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5import { Ping, Pong } from "./rpc-cycle.ts";
6
7export default Ping.make(
8 {
9 main: import.meta.url,
10 region: "iad",
11 guest: { cpuKind: "shared", cpus: 1, memoryMb: 256 },
12 },
13 Effect.gen(function* () {
14 const pong = yield* Fly.bindService(Pong);
15 return {
16 name: () => Effect.succeed("ping"),
17 fetch: Effect.gen(function* () {
18 return HttpServerResponse.text(`ping hears ${yield* pong.name()}`);
19 }).pipe(
20 Effect.catchCause((cause) =>
21 Effect.succeed(
22 HttpServerResponse.text(Cause.pretty(cause), { status: 502 }),
23 ),
24 ),
25 ),
26 };
27 }),
28);