# Future

```python
class Future
```

Represents a future for retrieving the result of asynchronous inference.

This class provides a mechanism similar to C++11 std::future, allowing access to the result of an asynchronous inference operation initiated via [`Model.infer_async()`](<https://docs.mobilint.com/runtime/en/v1.5/api/python/Model/#infer-async>). For details on C++11 std::future, refer to https://en.cppreference.com/w/cpp/thread/future.html .

The [Future](<https://docs.mobilint.com/runtime/en/v1.5/api/python/Future/index.md>) object enables the caller to:

- Wait for the inference to complete (`wait_for`)
- Block until completion and retrieve the output (`get`)

## Methods

| Name | Description |
| --- | --- |
| [`__init__`](<#init>) |  |
| [`from_cpp`](<#from-cpp>) |  |
| [`wait_for`](<#wait-for>) | Waits for asynchronous inference to complete or until the timeout elapses. |
| [`get`](<#get>) | Blocks until asynchronous inference completes and retrieves the output. |

### \_\_init\_\_

```python
def __init__(
    self,
    _future: Optional[
        Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8]
    ] = None,
    _inputs: Optional[List[np.ndarray]] = None,
):
    # If parameters are None, it indicates invalid access.
    # Set FutureFloat by default just to raise error with `get` method.
```

### from\_cpp

```python
def from_cpp(
    cls,
    _future: Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8],
    _inputs: List[np.ndarray],
)
```

### wait\_for

```python
def wait_for(self, timeout_ms: int) -> bool
```

Waits for asynchronous inference to complete or until the timeout elapses.

> [!NOTE]
>
> This method is safe to call multiple times. Calling it with a timeout of zero (i.e., `wait_for(0)`) performs a non-blocking check to see whether asynchronous inference has already completed.

**Parameters**

- `timeout_ms` *\[in\]* — Maximum duration to wait, in milliseconds.

**Returns**

True if inference completed before the timeout, false otherwise.

### get

```python
def get(self) -> List[np.ndarray]
```

Blocks until asynchronous inference completes and retrieves the output.

> [!NOTE]
>
> This method should be called only once per [Future](<https://docs.mobilint.com/runtime/en/v1.5/api/python/Future/index.md>). If called again, the return value will be invalid, and it will raise qbruntime.QbRuntimeError "Future\_NotValid".

**Returns**

A list of numpy ndarray containing the inference output.
