Arcadic.Transport.Grpc.ChannelPool (Arcadic v0.7.0)

Copy Markdown View Source

Caller-supervised shared-channel cache for Arcadic.Transport.Grpc.

A gRPC channel is HTTP/2-multiplexed — many concurrent streams share ONE connection — so this is a shared channel cache (one long-lived channel per {host, port, tls?} endpoint reused across ALL calls), NOT an exclusive checkout pool that would serialize streams. It opt-in: add

children = [{Arcadic.Transport.Grpc.ChannelPool, []}]

to your supervision tree. When it is running, the transport reuses its channel; when it is absent, the transport falls back to a fresh per-call connect (no behavior change). Tenant-blind — keyed on the endpoint only, carrying no database/scope. See docs/CHARTER.md (CA-1) and the transport ADR.

The cache serializes checkout through the GenServer so two concurrent first-connects don't race into two channels; a dead channel (its gun connection process gone) is transparently reconnected.

Summary

Functions

Return a healthy channel for key, connecting via connect_fn (a 0-arity -> {:ok, channel} | {:error, term}) and caching it if the endpoint has no live channel yet.

Returns a specification to start this module under a supervisor.

Functions

checkout(key, connect_fn)

@spec checkout(term(), (-> {:ok, term()} | {:error, term()})) ::
  {:ok, term()} | {:error, term()}

Return a healthy channel for key, connecting via connect_fn (a 0-arity -> {:ok, channel} | {:error, term}) and caching it if the endpoint has no live channel yet.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()