Skip to content
View as Markdown

APIFuture

Generated from tinker 0.30.4 at commit 1e5777e. Source links point at that snapshot.

class tinker.APIFuture(...)

Abstract base class for futures that can be awaited or accessed synchronously.

APIFuture provides a unified interface for handling async operations that can be accessed both synchronously (via result()) and asynchronously (via await or result_async()). This allows for flexible usage patterns in both sync and async contexts.

The future can be awaited directly in async contexts:

result = await api_future  # Equivalent to await api_future.result_async()

Or accessed synchronously:

result = api_future.result()  # Blocks until complete

Parameters:

  • T – The type of the result value

Example:

# In async context
future = training_client.forward_backward(data, "cross_entropy")
result = await future  # Or await future.result_async()

# In sync context
future = training_client.forward_backward(data, "cross_entropy")
result = future.result()

result(timeout=None)

Get the result synchronously with optional timeout.

Parameters:

  • timeout (float | None, default: None) – Maximum time to wait in seconds. None means wait indefinitely.

Returns:

  • The result value of type T

Raises:

TimeoutError: If timeout is exceeded

Async variant: result_async()

Referenced by