API Reference¶
-
trio_future.run(nursery: trio.Nursery, async_fn: Callable[[…], Awaitable[Any]], *args) → trio_future.future.Future¶ Run an async function and capture its result in a Future. This is the main entrypoint for trio-future.
Note that this is a synchronous function; it will immediately a
Futureobject. This object can be used to access the return value ofasync_fn. However, the function will not have begun execution. Under the hood, we will pass the function tonursery.start_soon; its execution will begin when we next defer to the scheduler.- Parameters
nursery (trio.Nursery) – Nursery in which to run the function
async_fn (Callable[.., Awaitable[Any]]) – A trio-flavored async function to run. Positional arguments may be passed as trailing args, keyword arguments must use
functools.partialor similar.
- Returns
A Future object allowing access to the return value of
async_fn.- Return type
-
trio_future.gather(nursery: trio.Nursery, futures: List[trio_future.future.Future]) → trio_future.future.Future¶ Concurrently run multiple Futures.
This function will allow the provided Futures to run concurrently, and gather their results into a single
Futurecontaining the results of all the inputs. That is, if each input Future contained anint, then the returned Future will contain aList[int]. In practice, the types need not be homogenous. The list enclosed in the returned Future will have the same ordering as the input list.If any Futures throw an exception, then the output Future will contain those exceptions, wrapped in a
trio.MultiError.
-
class
trio_future.Future(result_chan: trio.abc.ReceiveChannel, nursery: trio.Nursery)¶ Container class for the results of an async function.
-
async
get()¶ Await the result of this
Futureand unwrap the value. This will return a plain object if successful. If the bound function raised an exception, this will re-raise it.- Returns
The result of the bound unfunction, unwrapped
- Return type
The return type of the bound function.
-
async
outcome() → outcome.Outcome¶ Await the result of this
Futureand return it as an instance ofoutcome.Outcome, which can be one ofValueorError. Can only be called once for this object instance.- Raises
RuntimeError – If this method is called more than once on an object instance.
- Returns
Outcome of the function captured by this
Future.- Return type
outcome.Outcome
-
async