Packages

Self-healing clusters for Gleam applications on the BEAM!

Current section

Files

Jump to
barnacle src barnacle@local_epmd.erl
Raw

src/barnacle@local_epmd.erl

-module(barnacle@local_epmd).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([discover_nodes/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.
-file("src/barnacle/local_epmd.gleam", 10).
-spec get_hostname() -> binary().
get_hostname() ->
Host = begin
_pipe = erlang:node(),
_pipe@1 = gleam_erlang_ffi:identity(_pipe),
erlang:atom_to_binary(_pipe@1)
end,
_assert_subject = gleam@string:split(Host, <<"@"/utf8>>),
[_, Hostname] = case _assert_subject of
[_, _] -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"barnacle/local_epmd"/utf8>>,
function => <<"get_hostname"/utf8>>,
line => 16})
end,
Hostname.
-file("src/barnacle/local_epmd.gleam", 22).
?DOC(
" Discover nodes using the local EPMD. This will discover nodes on the same\n"
" hostname as the current node.\n"
).
-spec discover_nodes() -> {ok, list(gleam@erlang@atom:atom_())} | {error, nil}.
discover_nodes() ->
Hostname = get_hostname(),
_pipe = barnacle_ffi:list_local_nodes(),
gleam@result:map(
_pipe,
fun(_capture) ->
gleam@list:map(
_capture,
fun(N) ->
_pipe@1 = (<<<<N/binary, "@"/utf8>>/binary,
Hostname/binary>>),
erlang:binary_to_atom(_pipe@1)
end
)
end
).