# `Tinkex.TrainingClient.Polling`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/training_client/polling.ex#L1)

Future polling and result awaiting for TrainingClient.

This module handles:
- Awaiting forward/backward results from polling tasks
- Unlink tasks to prevent process coupling
- Safe await with error handling
- Response conversion to typed structs

# `await_forward_backward_results`

```elixir
@spec await_forward_backward_results([Task.t()], module()) ::
  {:ok, [Tinkex.Types.ForwardBackwardOutput.t()]} | {:error, Tinkex.Error.t()}
```

Await forward-backward polling tasks and convert results to typed structs.

Returns the results in order. If any task fails, remaining tasks are killed
and an error is returned.

# `await_forward_results`

```elixir
@spec await_forward_results([Task.t()], module()) ::
  {:ok, [Tinkex.Types.ForwardBackwardOutput.t()]} | {:error, Tinkex.Error.t()}
```

Await forward-only polling tasks and convert results to typed structs.

Similar to await_forward_backward_results but specifically for forward passes.

# `await_forward_results_for_custom_loss`

```elixir
@spec await_forward_results_for_custom_loss([Task.t()], module()) ::
  {:ok, [Tinkex.Types.ForwardBackwardOutput.t()]} | {:error, Tinkex.Error.t()}
```

Await forward results specifically for custom loss computation.

Same as await_forward_results but with clearer naming for custom loss context.

# `poll_and_await_unload`

```elixir
@spec poll_and_await_unload(map(), map(), keyword()) ::
  {:ok, Tinkex.Types.UnloadModelResponse.t()} | {:error, Tinkex.Error.t()}
```

Poll an unload future and await its result.

Polls the future, unlinks the task, and converts the result to an UnloadModelResponse.

# `poll_opts`

```elixir
@spec poll_opts(
  map(),
  keyword()
) :: keyword()
```

Build base poll options from state and user-provided options.

# `poll_opts_with_type`

```elixir
@spec poll_opts_with_type(map(), keyword(), String.t()) :: keyword()
```

Build poll options with request type metadata.

# `safe_await`

```elixir
@spec safe_await(module(), Task.t(), timeout()) ::
  {:ok, any()} | {:error, Tinkex.Error.t()}
```

Safely await a task with timeout and error handling.

Wraps Task.await with exception and exit handling to ensure errors are
returned in a consistent format.

# `unlink_task`

```elixir
@spec unlink_task(Task.t() | any()) :: :ok
```

Unlink a task to prevent process coupling.

This allows the task to continue running even if the calling process terminates.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
