google.appengine.datastore.datastore_rpc.MultiRpc

A wrapper around multiple UserRPC objects.

Inherits From: expected_type

This provides an API similar to that of UserRPC, but wraps multiple RPCs such that e.g. .wait() blocks until all wrapped RPCs are complete, and .get_result() returns the combined results from all wrapped RPCs.

Class methods:

flatten(rpcs): Expand a list of UserRPCs and MultiRpcs into a list of UserRPCs. wait_any(rpcs): Call UserRPC.wait_any(flatten(rpcs)). wait_all(rpcs): Call UserRPC.wait_all(flatten(rpcs)).

Instance methods:

wait(): Wait for all RPCs. check_success(): Wait and then check success for all RPCs. get_result(): Wait for all, check successes, then merge all results.

Instance attributes:

  • rpcs: The list of wrapped RPCs (returns a copy).
  • state: The combined state of all RPCs.

rpcs A list of UserRPC and MultiRpc objects; it is flattened before being stored.
extra_hook Optional function to be applied to the final result or list of results.

rpcs Get a flattened list containing the RPCs wrapped.

This returns a copy to prevent users from modifying the state.

state Get the combined state of the wrapped RPCs.

This mimics the UserRPC.state property. If all wrapped RPCs have the same state, that state is returned; otherwise, RUNNING is returned (which here really means 'neither fish nor flesh').

Methods

check_success

View source

Check success of all wrapped RPCs, failing if any of the failed.

This mimics the UserRPC.check_success() method.

NOTE: This first waits for all wrapped RPCs to finish before checking the success of any of them. This makes debugging easier.

flatten

View source

Return a list of UserRPCs, expanding MultiRpcs in the argument list.

For example: given 4 UserRPCs rpc1 through rpc4, flatten(rpc1, MultiRpc([rpc2, rpc3], rpc4) returns [rpc1, rpc2, rpc3, rpc4].

Args
rpcs A list of UserRPC and MultiRpc objects.

Returns
A list of UserRPC objects.

get_result

View source

Return the combined results of all wrapped RPCs.

This mimics the UserRPC.get_results() method. Multiple results are combined using the following rules:

  1. If there are no wrapped RPCs, an empty list is returned.

  2. If exactly one RPC is wrapped, its result is returned.

  3. If more than one RPC is wrapped, the result is always a list, which is constructed from the wrapped results as follows:

    a. A wrapped result equal to None is ignored;

    b. A wrapped result that is a list (but not any other type of sequence!) has its elements added to the result list.

    c. Any other wrapped result is appended to the result list.

After all results are combined, if __extra_hook is set, it is called with the combined results and its return value becomes the final result.

NOTE: This first waits for all wrapped RPCs to finish, and then checks all their success. This makes debugging easier.

wait

View source

Wait for all wrapped RPCs to finish.

This mimics the UserRPC.wait() method.

wait_all

View source

Wait until all RPCs passed in are finished.

This mimics UserRPC.wait_all().

Args
rpcs A list of UserRPC and MultiRpc objects.

wait_any

View source

Wait until one of the RPCs passed in is finished.

This mimics UserRPC.wait_any().

Args
rpcs A list of UserRPC and MultiRpc objects.

Returns
A UserRPC object or None.