NodeWire.Client (NodeWire v0.1.0)

Copy Markdown View Source

Persistent outbound client; sessions and handler state are fresh on reconnect.

Summary

Types

Latest asynchronous connection state, snapshot and failure reason.

Functions

Builds a child spec, validating the endpoint options. See NodeWire.

Kills the current session and disables retries until reconnect/1 is called.

Kills any existing session and starts a fresh asynchronous connection attempt.

Sends through the current connection; returns :not_connected if unavailable.

Starts a linked persistent client using the endpoint options in NodeWire.

Returns the latest connection snapshot and failure reason.

Types

status()

@type status() :: %{
  state: :negotiated | :disconnected,
  connection: NodeWire.Conn.t() | nil,
  reason: atom() | NodeWire.Error.t() | nil
}

Latest asynchronous connection state, snapshot and failure reason.

Functions

child_spec(init_arg)

@spec child_spec(NodeWire.options()) :: Supervisor.child_spec()

Builds a child spec, validating the endpoint options. See NodeWire.

disconnect(client)

@spec disconnect(GenServer.server()) :: :ok

Kills the current session and disables retries until reconnect/1 is called.

This does not perform a graceful CLOSE exchange. Exits if the client is unavailable.

reconnect(client)

@spec reconnect(GenServer.server()) :: :ok

Kills any existing session and starts a fresh asynchronous connection attempt.

Re-enables attempts after disconnect/1 or a permanent failure. The configured automatic reconnect policy still applies to later failures. Exits if unavailable.

send(client, message, opts \\ [])

Sends through the current connection; returns :not_connected if unavailable.

Accepts :timeout_ms (default 5,000) and :on_sent tracking tags, as in NodeWire.Server.send/4. Messages are never automatically replayed after reconnect. See NodeWire for local-write success and unknown outcomes. Return send actions from handlers instead of synchronously sending to yourself.

start_link(c)

@spec start_link(NodeWire.options()) :: GenServer.on_start()

Starts a linked persistent client using the endpoint options in NodeWire.

Connecting, authentication and readiness are asynchronous. Invalid configuration raises; observe status/1 for subsequent connection failures. Handler state is initialized afresh on every connection attempt.

status(client)

@spec status(GenServer.server()) :: status()

Returns the latest connection snapshot and failure reason.

:negotiated does not imply application readiness; inspect the snapshot's phase. :disconnected also covers attempts in progress. Successful attempts clear earlier reasons. Exits if the client process is unavailable.