Issue with Layer.updateService Returning Old Service Implementation

Hey guys, could you pls help me with Layer.updateService?

In the following (oversimplified test) code I get the old service from the updated layer, however, it should return the updated service implementation.

I've spent hours with this, even looking all details in the platform's core code, and nothing... I may have missed something

import { Context, Effect, Layer } from "effect";

interface Service1 {
  type: string;
}

export const Service1: Context.Tag<Service1, Service1> =
  Context.GenericTag<Service1>("@test/Service1");

const BaseLayer = Layer.effect(
  Service1,
  Effect.succeed({ type: "Base" }).pipe(
    Effect.tap(() => console.log("BaseLayer built"))
  )
);

const UpdatedLayer = BaseLayer.pipe(
  Layer.updateService(Service1, (s) => {
    console.log(s);
    return {
      type: "Updated",
    };
  })
).pipe(Layer.provide(BaseLayer));

const program = Effect.gen(function* () {
  const s1 = yield* Service1;
  console.log(s1); // logs { type: 'Base' } but why??
}).pipe(Effect.provide(UpdatedLayer));

Effect.runSync(program);
Was this page helpful?