import * as Context from "effect/Context"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; import type * as Scope from "effect/Scope"; export class ServerActivation extends Context.Reference | undefined>( "t3/serverActivation", { defaultValue: () => undefined }, ) {} /** Forks a long-running root before commit and proves it is parked at the activation boundary. */ export const forkParked = ( effect: Effect.Effect, ): Effect.Effect => Effect.gen(function* () { const activation = yield* ServerActivation; if (activation === undefined) { yield* Effect.forkScoped(effect); return; } const parked = yield* Deferred.make(); yield* Effect.forkScoped( Deferred.succeed(parked, undefined).pipe(Effect.andThen(activation), Effect.andThen(effect)), ); yield* Deferred.await(parked); });