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

A struct representing an asynchronous operation that can be awaited for results.

The Future module provides functionality to handle asynchronous operations in ProcessHub, allowing callers to wait for results from distributed process start/stop operations. This is particularly useful when you need to verify the outcome of operations.

Summary

Functions

Waits for the completion of an asynchronous operation and returns the results.

Types

@type await_result() ::
  ProcessHub.StartResult.t() | ProcessHub.StopResult.t() | {:error, term()}
@type future_input() :: t() | {:ok, t()} | {:error, term()} | term()
@type t() :: %ProcessHub.Future{
  future_resolver: pid(),
  ref: reference(),
  timeout: non_neg_integer()
}

Functions

@spec await(future_input()) :: await_result()

Waits for the completion of an asynchronous operation and returns the results.

This function blocks the calling process until the future resolves or times out. It communicates with the future resolver process to collect the final results of the distributed operation.

Handles multiple input types:

  • Future.t() struct - Awaits the future operation
  • {:ok, Future.t()} - Extracts and awaits the future
  • {:error, term()} - Returns the error unchanged
  • Other input - Returns {:error, :invalid_argument}

Parameters

  • future - A Future struct, {:ok, Future.t()} tuple, {:error, term()} tuple, or other input

Returns

  • ProcessHub.StartResult.t() for start operations
  • ProcessHub.StopResult.t() for stop operations
  • {:error, :timeout} if the operation times out
  • {:error, :invalid_argument} for invalid input
  • {:error, reason} for error tuples