Effect CommunityEC
Effect Community3y ago
3 replies
effectnoob

(Answered) Question on Providing Multiple Layers

Question on how to provide multiple layers.
For a while I was doing this

import * as T from '@effect/io/Effect'
import * as L from '@effect/io/Layer'

... eventually

T.runPromise(
  this.workflow.main(req).pipe(
    T.provideLayer(this.outputLayer),
    T.provideLayer(this.dbLayer)
  )
);


and things were working. Then I added another layer and tried providing it like this

T.runPromise(
  this.workflow.main(req).pipe(
    T.provideLayer(this.outputLayer),
    T.provideLayer(this.dbLayer),
    T.provideLayer(this.genLayer) ◀──────────── added a layer
  )
);


but that gave me odd errors like

Property 'send' is missing in type 'Db' but required in type 'WorkflowOutput'.


So after some searching I discovered https://github.com/tim-smart/dfx/blob/main/src/gateway.ts#L40
which made use of mergeAll so on a hunch I tried

T.runPromise(
  this.workflow.main(req).pipe(
    T.provideLayer(
      L.mergeAll(
        this.outputLayer,
        this.dbLayer,
        this.genLayer 
      )
    )
  )
);


and the compiler was happy. All was good again... I think... I haven't implemented enough yet to
actually run any tests so I'm wondering if this use of layers is going to blow up on me later when I do...

So my questions are:

* Is mergeAll the way to go if I want to provide 3 orthogonal layers which don't depend on each other?
* Am I perhaps stumbling across a known bug/limit calling provideLayer?
Was this page helpful?