import { NextResponse } from "next/server"
import { Effect } from "effect"
const getId = async (id: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000))
return id
}
const getIdEffect = (id: string) =>
Effect.promise(() => getId(id)).pipe(Effect.withRequestCaching(true))
export const GET = async () => {
const effect = Effect.gen(function* () {
yield* getIdEffect("123")
yield* getIdEffect("123")
return yield* getIdEffect("123")
})
const response = await Effect.runPromise(effect)
return NextResponse.json(response)
}
import { NextResponse } from "next/server"
import { Effect } from "effect"
const getId = async (id: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000))
return id
}
const getIdEffect = (id: string) =>
Effect.promise(() => getId(id)).pipe(Effect.withRequestCaching(true))
export const GET = async () => {
const effect = Effect.gen(function* () {
yield* getIdEffect("123")
yield* getIdEffect("123")
return yield* getIdEffect("123")
})
const response = await Effect.runPromise(effect)
return NextResponse.json(response)
}