gleam/erlang/node

Multiple Erlang VM instances can form a cluster to make a distributed Erlang system, talking directly to each other using messages rather than other communication protocols like HTTP. In a distributed Erlang system each virtual machine is called a node. This module provides Node related types and functions to be used as a foundation by other packages providing more specialised functionality.

For more information on distributed Erlang systems see the Erlang documentation: https://www.erlang.org/doc/system/distributed.html.

Types

pub type ConnectError {
  FailedToConnect
  LocalNodeIsNotAlive
}

Constructors

  • FailedToConnect

    Was unable to connect to the node.

  • LocalNodeIsNotAlive

    The local node is not alive, so it is not possible to connect to the other node.

pub type Node

Values

pub fn connect(node: atom.Atom) -> Result(Node, ConnectError)

Establish a connection to a node, so the nodes can send messages to each other and any other connected nodes.

Returns Error(FailedToConnect) if the node is not reachable.

Returns Error(LocalNodeIsNotAlive) if the local node is not alive, meaning it is not running in distributed mode.

pub fn name(node: Node) -> atom.Atom

Get the atom name of a node.

Examples

assert name(my_node) == atom.create("app1@localhost")
pub fn self() -> Node

Return the current node.

pub fn visible() -> List(Node)

Return a list of all visible nodes in the cluster, not including the current node.

The current node can be included by calling self() and prepending the result.

let all_nodes = [node.self(), ..node.visible()]
Search Document