Packages

Typed distributed messaging for Gleam on the BEAM.

Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.

Current section

Files

Jump to
distribute src distribute@discovery@types.erl
Raw

src/distribute@discovery@types.erl

-module(distribute@discovery@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/distribute/discovery/types.gleam").
-export([new_handle/2, handle_id/1, handle_state/1, new_subscription_id/1, subscription_id_value/1, default_retry_config/0, is_transient_error/1, is_permanent_error/1]).
-export_type([adapter_handle/0, peer_info/0, health_status/0, health_info/0, subscription_id/0, discovery_event/0, adapter_options/0, retry_config/0, discovery_metrics/0, discovery_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Discovery layer type definitions.\n"
"\n"
" This module contains all shared types used by discovery adapters. These\n"
" types form the contract between the adapter implementations and the\n"
" higher-level discovery facade.\n"
"\n"
" ## Type Categories\n"
"\n"
" - **Handles** - Opaque references to running adapters\n"
" - **Status** - Health and subscription state\n"
" - **Errors** - Structured error types for operations\n"
" - **Peers** - Peer information and metadata\n"
).
-opaque adapter_handle() :: {adapter_handle, binary(), gleam@dynamic:dynamic_()}.
-type peer_info() :: {peer_info, binary(), gleam@dict:dict(binary(), binary())}.
-type health_status() :: up | {degraded, binary()} | {down, binary()}.
-type health_info() :: {health_info,
health_status(),
gleam@option:option(integer()),
gleam@option:option(binary()),
integer()}.
-opaque subscription_id() :: {subscription_id, binary()}.
-type discovery_event() :: {peer_up,
binary(),
gleam@dict:dict(binary(), binary())} |
{peer_update, binary(), gleam@dict:dict(binary(), binary())} |
{peer_down, binary(), binary()}.
-type adapter_options() :: {adapter_options,
binary(),
integer(),
integer(),
binary(),
list(binary()),
retry_config(),
gleam@option:option(fun((binary(), gleam@dict:dict(binary(), binary())) -> nil)),
gleam@dict:dict(binary(), gleam@dynamic:dynamic_())}.
-type retry_config() :: {retry_config, integer(), integer(), integer(), float()}.
-type discovery_metrics() :: {discovery_metrics,
integer(),
integer(),
integer(),
integer(),
integer(),
float()}.
-type discovery_error() :: {start_failed, binary()} |
{stop_failed, binary()} |
{shutdown_timeout, integer()} |
{sync_failed, binary()} |
{peer_not_found, binary()} |
{invalid_configuration, binary()} |
{timeout, integer()} |
{subscription_failed, binary()}.
-file("src/distribute/discovery/types.gleam", 33).
?DOC(
" Create a new adapter handle with an identifier and internal state.\n"
"\n"
" This is typically called by adapter implementations, not user code.\n"
).
-spec new_handle(binary(), gleam@dynamic:dynamic_()) -> adapter_handle().
new_handle(Id, State) ->
{adapter_handle, Id, State}.
-file("src/distribute/discovery/types.gleam", 38).
?DOC(" Get the handle's identifier (the name it was registered with).\n").
-spec handle_id(adapter_handle()) -> binary().
handle_id(Handle) ->
erlang:element(2, Handle).
-file("src/distribute/discovery/types.gleam", 45).
?DOC(
" Get the handle's internal state.\n"
"\n"
" Used by adapter implementations to retrieve their actor Subject.\n"
).
-spec handle_state(adapter_handle()) -> gleam@dynamic:dynamic_().
handle_state(Handle) ->
erlang:element(3, Handle).
-file("src/distribute/discovery/types.gleam", 100).
?DOC(" Create a new subscription ID.\n").
-spec new_subscription_id(binary()) -> subscription_id().
new_subscription_id(Id) ->
{subscription_id, Id}.
-file("src/distribute/discovery/types.gleam", 105).
?DOC(" Extract the string value from a subscription ID.\n").
-spec subscription_id_value(subscription_id()) -> binary().
subscription_id_value(Id) ->
{subscription_id, Value} = Id,
Value.
-file("src/distribute/discovery/types.gleam", 169).
?DOC(" Default retry configuration.\n").
-spec default_retry_config() -> retry_config().
default_retry_config() ->
{retry_config, 3, 100, 5000, 2.0}.
-file("src/distribute/discovery/types.gleam", 221).
?DOC(" Check if an error is transient and should be retried.\n").
-spec is_transient_error(discovery_error()) -> boolean().
is_transient_error(Error) ->
case Error of
{sync_failed, _} ->
true;
{timeout, _} ->
true;
_ ->
false
end.
-file("src/distribute/discovery/types.gleam", 230).
?DOC(" Check if an error is permanent and should not be retried.\n").
-spec is_permanent_error(discovery_error()) -> boolean().
is_permanent_error(Error) ->
case Error of
{invalid_configuration, _} ->
true;
{peer_not_found, _} ->
true;
{start_failed, _} ->
true;
_ ->
false
end.