Futures and sequences: f_traverse, f_sequence, f_zip

more_executors.f_zip(*fs)

Create a new future holding the return values of any number of input futures.

Signature: Future<A>[, Future<B>[, ...]] Future<A[, B[, ...]]>

Parameters

fs (Future) – Any number of futures.

Returns

Future of tuple

A future holding the returned values of all input futures as a tuple. The returned tuple has the same length and order as the input futures.

Alternatively, a future raising an exception or a cancelled future, if any input futures raised an exception or was cancelled.

Note

This function is tested with up to 100,000 input futures. Exceeding this limit may result in performance issues.

New in version 1.19.0.

more_executors.f_sequence(futures)

Transform a list of futures into a future containing a list.

Signature: list<Future<X>> Future<list<X>>

Parameters

futures (iterable of Future) – A list or other iterable of futures.

Returns

Future of list

A future resolved with either:

  • a list holding the output value of each input future

  • or an exception, if any input future raised an exception

Note

This function is tested with up to 100,000 input futures. Exceeding this limit may result in performance issues.

New in version 1.19.0.

more_executors.f_traverse(fn, xs)

Traverse over an iterable calling a future-returning function, and return a future holding the returned values as a list.

Signature: fn<A⟶Future<B>>, iterable<A> Future<list<B>>

Parameters
  • fn (callable) – A unary function returning a future.

  • xs (iterable) – An iterable to be traversed.

Returns

Future of list

A future resolved with either:

  • a list holding the resolved output values of fn

  • or an exception, if fn or any future produced by fn failed

New in version 1.19.0.