# Future

Source: https://www.tensorplay.cn/docs/generated/tensorplay.futures.Future.html

# Future

class tensorplay.futures.Future(*, _completer: [Callable](https://docs.python.org/3/library/typing.html#typing.Callable)[[], [Any](https://docs.python.org/3/library/typing.html#typing.Any)] | [None](https://docs.python.org/3/library/constants.html#None) = None)[[source]](../_modules/tensorplay/futures.html#Future)

Holder for an asynchronous result (torch parity subset).

Example:

```
>>> fut = tp.futures.Future()
>>> fut.set_result(1)
>>> fut.value()
1
>>> chained = other.then(lambda f: f.value()[0])
>>> chained.value()
tensor(...)
```

add_done_callback(callback: [Callable](https://docs.python.org/3/library/typing.html#typing.Callable)[[[Future](#tensorplay.futures.Future)], [Any](https://docs.python.org/3/library/typing.html#typing.Any)]) &#x2192; [None](https://docs.python.org/3/library/constants.html#None)[[source]](../_modules/tensorplay/futures.html#Future.add_done_callback)

Appends a callback run when this future completes.

done() &#x2192; [bool](https://docs.python.org/3/library/functions.html#bool)[[source]](../_modules/tensorplay/futures.html#Future.done)

Returns whether the future is complete (non-blocking).

is_done() &#x2192; [bool](https://docs.python.org/3/library/functions.html#bool)[[source]](../_modules/tensorplay/futures.html#Future.is_done)

Alias of [done()](#tensorplay.futures.Future.done).

set_result(result: [Any](https://docs.python.org/3/library/typing.html#typing.Any)) &#x2192; [None](https://docs.python.org/3/library/constants.html#None)[[source]](../_modules/tensorplay/futures.html#Future.set_result)

Sets the result value and fires callbacks (torch parity).

then(callback: [Callable](https://docs.python.org/3/library/typing.html#typing.Callable)[[[Future](#tensorplay.futures.Future)], [Any](https://docs.python.org/3/library/typing.html#typing.Any)]) &#x2192; [Future](#tensorplay.futures.Future)[[source]](../_modules/tensorplay/futures.html#Future.then)

Adds a callback mapped over this future; returns the new future.

The callback receives this future and its return value becomes the
derived future’s result (torch Future.then contract).

value() &#x2192; [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](../_modules/tensorplay/futures.html#Future.value)

Gets the result value, blocking until it completes.

Raises RuntimeError on error results (mirrors torch’s
ValueError-on-error behavior loosely; tp stores exceptions as
results and re-raises them here).

wait() &#x2192; [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](../_modules/tensorplay/futures.html#Future.wait)

Blocks until complete and returns the result value.
