(builder: PeerProtocolBuilder): Layer.Layer<never>Set the wire a fleet's peers mesh dials on — the (url) => Layer<RpcClient.Protocol>
builder (protocolHttp by default, or protocolWebsocket). Provide it alongside
peersLayer on any node whose peers serve a non-http transport, so cross-node folds
(fleetActive, activeByNode) reach peers that speak websocket. The peer urls stay on the
Nodes; this only chooses how to dial them:
Node.pipe(
Layer.provide(Hyperlink.peersLayer(WorkerPool, ThisNode)),
Layer.provide(Hyperlink.layerPeerProtocol(Hyperlink.protocolWebsocket)),
);export const const layerPeerProtocol: (
builder: PeerProtocolBuilder
) => Layer.Layer<never>
Set the wire a fleet's
peers
mesh dials on — the (url) => Layer<RpcClient.Protocol>
builder (
protocolHttp
by default, or
protocolWebsocket
). Provide it alongside
peersLayer
on any node whose peers serve a non-http transport, so cross-node folds
(fleetActive, activeByNode) reach peers that speak websocket. The peer urls stay on the
Node
s; this only chooses how to dial them:
Node.pipe(
Layer.provide(Hyperlink.peersLayer(WorkerPool, ThisNode)),
Layer.provide(Hyperlink.layerPeerProtocol(Hyperlink.protocolWebsocket)),
);
layerPeerProtocol = (
builder: PeerProtocolBuilderbuilder: type PeerProtocolBuilder = (
url: string
) => Layer.Layer<RpcClient.Protocol>
The wire a fleet's
peers
mesh dials on — a (url) => Layer<RpcClient.Protocol> builder.
A Context.Reference defaulting to
protocolHttp
, so
peersLayer
reads it with no added
requirement;
layerPeerProtocol
overrides it per node (e.g. to
protocolWebsocket
).
PeerProtocolBuilder,
): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<never> => import LayerLayer.const succeedContext: <never>(
context: Context.Context<never>
) => Layer.Layer<never, never, never>
Constructs a layer that provides all services in an already available
Context.
When to use
Use when you need a Layer built from an existing Context, including when
you need to provide multiple services at once.
Details
This is a more general version of succeed that allows you to provide
multiple services at once through a Context.
Example (Providing multiple services from a context)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
class Logger extends Context.Service<Logger, {
readonly log: (msg: string) => Effect.Effect<void>
}>()("Logger") {}
const context = Context.make(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result"))
}).pipe(
Context.add(Logger, {
log: (msg: string) => Effect.sync(() => console.log(msg))
})
)
const layer = Layer.succeedContext(context)
succeedContext(import ContextContext.const make: <never, PeerProtocolBuilder>(
key: Context.Key<never, PeerProtocolBuilder>,
service: PeerProtocolBuilder
) => Context.Context<never>
Creates a new Context with a single service associated to the key.
Example (Creating a context with one service)
import { Context } from "effect"
import * as assert from "node:assert"
const Port = Context.Service<{ PORT: number }>("Port")
const context = Context.make(Port, { PORT: 8080 })
assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
make(const peerProtocolRef: Context.Reference<PeerProtocolBuilder>const peerProtocolRef: {
defaultValue: () => Shape;
of: (this: void, self: PeerProtocolBuilder) => PeerProtocolBuilder;
context: (self: PeerProtocolBuilder) => Context.Context<never>;
use: (f: (service: PeerProtocolBuilder) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: PeerProtocolBuilder) => A) => Effect.Effect<A, never, never>;
Identifier: Identifier;
Service: Shape;
key: string;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
peerProtocolRef, builder: PeerProtocolBuilderbuilder));