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

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

This module provides utilities for formatting and extracting information from stop operation results, including successful stops and errors.

Summary

Functions

Returns all child IDs from stopped processes.

Extracts the errors from a StopResult struct or error tuple.

Returns the first stopped child entry.

Formats a StopResult struct into a standardized tuple format.

Returns all unique nodes where child processes were stopped.

Extracts the status from a StopResult struct or error tuple.

Types

@type error_input() :: {:error, term()}
@type t() :: %ProcessHub.StopResult{
  errors: [{ProcessHub.child_id(), term()}],
  status: :ok | :error,
  stopped: [{ProcessHub.child_id(), [node()]}]
}

Functions

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

Returns all child IDs from stopped processes.

Parameters

  • result - A StopResult struct

Returns

  • List of child IDs

Examples

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

Extracts the errors from a StopResult struct or error tuple.

Parameters

  • result - A StopResult struct or error tuple

Returns

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

Examples

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

Returns the first stopped child entry.

Parameters

  • result - A StopResult struct

Returns

  • {child_id, nodes} tuple if processes were stopped
  • nil if no processes were stopped

Examples

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

Formats a StopResult struct into a standardized tuple format.

Parameters

  • result - A StopResult struct or error tuple

Returns

  • {:ok, stopped} for successful operations
  • {:error, {errors, stopped}} for failed operations
  • {:error, reason} for error tuples

Examples

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

iex> ProcessHub.StopResult.format({:error, :timeout})
{:error, :timeout}
@spec nodes(t()) :: [node()]

Returns all unique nodes where child processes were stopped.

Parameters

  • result - A StopResult struct

Returns

  • List of unique nodes

Examples

iex> result = %ProcessHub.StopResult{stopped: [{"child1", [:node1, :node2]}]}
iex> ProcessHub.StopResult.nodes(result)
[:node1, :node2]
@spec status(t() | error_input()) :: :ok | :error | error_input()

Extracts the status from a StopResult struct or error tuple.

Parameters

  • result - A StopResult struct or error tuple

Returns

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

Examples

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