| 1 | import * as Fly from "@/Fly"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import { Ping, Pong } from "./rpc-cycle.ts"; |
| 6 | |
| 7 | export 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 | ); |