A wrapper around multiple UserRPC objects.
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.
def google.appengine.datastore.datastore_rpc.MultiRpc.flatten |
( |
|
cls, |
|
|
|
rpcs |
|
) |
| |
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.
def google.appengine.datastore.datastore_rpc.MultiRpc.get_result |
( |
|
self | ) |
|
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.