@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 27 lines 1.01 KB
Raw
1 import { waitUntil as nativeWaitUntil } from "@neon/functions";
2 import type { RuntimeContext } from "alchemy/RuntimeContext";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as Scope from "effect/Scope";
6
7 /**
8 * Run bounded post-response work with its own scope. Failures are logged.
9 * Neon limits waitUntil work to fifteen minutes; this is not a durable job.
10 */
11 export const waitUntil = <A, E, R>(
12 effect: Effect.Effect<A, E, R>,
13 ): Effect.Effect<void, never, RuntimeContext | Exclude<R, Scope.Scope>> =>
14 Effect.gen(function* () {
15 const context = yield* Effect.context<Exclude<R, Scope.Scope>>();
16 const memoMap = yield* Layer.makeMemoMap;
17 yield* Effect.sync(() =>
18 effect.pipe(
19 Effect.scoped,
20 Effect.provideService(Layer.CurrentMemoMap, memoMap),
21 Effect.timeout("15 minutes"),
22 Effect.tapCause(() => Effect.logError("Neon waitUntil task failed")),
23 Effect.runPromiseWith(context),
24 nativeWaitUntil,
25 ),
26 );
27 });