View Source ProcessHub.StartResult (ProcessHub v0.4.0-beta)

A struct representing the result of starting child processes across multiple nodes.

This module provides utilities for formatting and extracting information from start operation results, including successful starts, errors, and rollback scenarios.

Summary

Functions

Returns all child IDs from started processes.

Extracts the errors from a StartResult struct or error tuple.

Returns the first started child entry.

Formats a StartResult struct into a standardized tuple format.

Returns the first node from the first started child process.

Returns all unique nodes where child processes were started.

Returns the first PID from the first started child process.

Returns all PIDs from all started child processes.

Extracts the status from a StartResult struct or error tuple.

Types

@type error_input() :: {:error, term()}
@type t() :: %ProcessHub.StartResult{
  errors: [{ProcessHub.child_id(), term()}],
  rollback: boolean(),
  started: [{ProcessHub.child_id(), [{node(), pid()}]}],
  status: :ok | :error
}

Functions

@spec cids(t()) :: [ProcessHub.child_id()]

Returns all child IDs from started processes.

Parameters

  • result - A StartResult struct

Returns

  • List of child IDs

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [...]}, {"child2", [...]}]}
iex> ProcessHub.StartResult.cids(result)
["child1", "child2"]
@spec errors(t() | error_input()) :: [{ProcessHub.child_id(), term()}] | error_input()

Extracts the errors from a StartResult struct or error tuple.

Parameters

  • result - A StartResult struct or error tuple

Returns

  • List of {child_id, error_reason} tuples for StartResult structs
  • {:error, reason} for error tuples

Examples

iex> result = %ProcessHub.StartResult{errors: [{"child1", :timeout}]}
iex> ProcessHub.StartResult.errors(result)
[{"child1", :timeout}]
@spec first(t()) :: {ProcessHub.child_id(), [{node(), pid()}]} | nil

Returns the first started child entry.

Parameters

  • result - A StartResult struct

Returns

  • {child_id, node_pids} tuple if processes were started
  • nil if no processes were started

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [{:node1, pid}]}]}
iex> ProcessHub.StartResult.first(result)
{"child1", [{:node1, pid}]}
@spec format(t() | error_input()) ::
  {:ok, term()}
  | {:error, {term(), term()}}
  | {:error, {term(), term()}, :rollback}
  | {:error, term()}

Formats a StartResult struct into a standardized tuple format.

Parameters

  • result - A StartResult struct or error tuple

Returns

  • {:ok, started} for successful operations
  • {:error, {errors, started}} for failed operations
  • {:error, {errors, started}, :rollback} for failed operations with rollback
  • {:error, reason} for error tuples

Examples

iex> result = %ProcessHub.StartResult{status: :ok, started: [{"child1", [node1: pid]}]}
iex> ProcessHub.StartResult.format(result)
{:ok, [{"child1", [node1: pid]}]}

iex> ProcessHub.StartResult.format({:error, :timeout})
{:error, :timeout}
@spec node(t()) :: node() | nil

Returns the first node from the first started child process.

Parameters

  • result - A StartResult struct

Returns

  • node() if processes were started
  • nil if no processes were started

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [{:node1, pid}]}]}
iex> ProcessHub.StartResult.node(result)
:node1
@spec nodes(t()) :: [node()]

Returns all unique nodes where child processes were started.

Parameters

  • result - A StartResult struct

Returns

  • List of unique nodes

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [{:node1, pid1}, {:node2, pid2}]}]}
iex> ProcessHub.StartResult.nodes(result)
[:node1, :node2]
@spec pid(t()) :: pid() | nil

Returns the first PID from the first started child process.

Parameters

  • result - A StartResult struct

Returns

  • pid() if processes were started
  • nil if no processes were started

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [{:node1, pid}]}]}
iex> ProcessHub.StartResult.pid(result)
pid
@spec pids(t()) :: [pid()]

Returns all PIDs from all started child processes.

Parameters

  • result - A StartResult struct

Returns

  • List of PIDs from all started processes

Examples

iex> result = %ProcessHub.StartResult{started: [{"child1", [{:node1, pid1}, {:node2, pid2}]}]}
iex> ProcessHub.StartResult.pids(result)
[pid1, pid2]
@spec status(t() | error_input()) :: :ok | :error | error_input()

Extracts the status from a StartResult struct or error tuple.

Parameters

  • result - A StartResult struct or error tuple

Returns

  • :ok or :error for StartResult structs
  • {:error, reason} for error tuples

Examples

iex> result = %ProcessHub.StartResult{status: :ok}
iex> ProcessHub.StartResult.status(result)
:ok