Effect CommunityEC
Effect Community5mo ago
3 replies
Joe Eckard

Cache lookup span not associated with parent

I would expect the following code

export class FooAuth extends Effect.Service<FooAuth>()("app/FooAuth", {
  effect: Effect.gen(function*() {
    const tokenCache = yield* Cache.make({
      capacity: 1,
      timeToLive: Duration.minutes(30),
      lookup: Effect.fn("FooAuth.refreshToken")(function*(_: void) {
        yield* Effect.sleep("2 seconds")
        return "some-token"
      })
    })

    const getToken = Effect.fn("FooAuth.getToken")(function*() {
      return yield* tokenCache.get()
    })

    return { getToken } as const
  }),
  dependencies: []
}) {}

const program = Effect.gen(function*() {
  const { getToken } = yield* FooAuth
  yield* getToken()
}).pipe(Effect.withSpan("program"))

to produce 1 trace:
program -> FooAuth.getToken -> FooAuth.refreshToken

but instead it produces 2:
program -> FooAuth.getToken
FooAuth.refreshToken

Could this be a bug, or is there something else I'm not understanding?
Was this page helpful?