Futures¶
Futures for dealing with asynchronous operations.
-
class
google.api_core.future.
Future
[source]¶ Bases:
object
Future interface.
This interface is based on
concurrent.futures.Future
.
Abstract and helper bases for Future implementations.
-
class
google.api_core.future.polling.
PollingFuture
(retry=<google.api_core.retry.Retry object>)[source]¶ Bases:
google.api_core.future.base.Future
A Future that needs to poll some service to check its status.
The
done()
method should be implemented by subclasses. The polling behavior will repeatedly calldone
until it returns True.- Parameters
retry (google.api_core.retry.Retry) – The retry configuration used when polling. This can be used to control how often
done()
is polled. Regardless of the retry’sdeadline
, it will be overridden by thetimeout
argument toresult()
.
-
add_done_callback
(fn)[source]¶ Add a callback to be executed when the operation is complete.
If the operation is not already complete, this will start a helper thread to poll for the status of the operation in the background.
- Parameters
fn (Callable[Future]) – The callback to execute when the operation is complete.
-
abstract
done
(retry=<google.api_core.retry.Retry object>)[source]¶ Checks to see if the operation is complete.
- Parameters
retry (google.api_core.retry.Retry) – (Optional) How to retry the RPC.
- Returns
True if the operation is complete, False otherwise.
- Return type
-
exception
(timeout=None)[source]¶ Get the exception from the operation, blocking if necessary.
- Parameters
timeout (int) – How long to wait for the operation to complete. If None, wait indefinitely.
- Returns
- The operation’s
error.
- Return type
Optional[google.api_core.GoogleAPICallError]
-
result
(timeout=None)[source]¶ Get the result of the operation, blocking if necessary.
- Parameters
timeout (int) – How long (in seconds) to wait for the operation to complete. If None, wait indefinitely.
- Returns
The Operation’s result.
- Return type
google.protobuf.Message
- Raises
google.api_core.GoogleAPICallError – If the operation errors or if the timeout is reached before the operation completes.
AsyncIO implementation of the abstract base Future class.
-
class
google.api_core.future.async_future.
AsyncFuture
(retry=<google.api_core.retry_async.AsyncRetry object>)[source]¶ Bases:
google.api_core.future.base.Future
A Future that polls peer service to self-update.
The
done()
method should be implemented by subclasses. The polling behavior will repeatedly calldone
until it returns True.- Parameters
retry (google.api_core.retry.Retry) – The retry configuration used when polling. This can be used to control how often
done()
is polled. Regardless of the retry’sdeadline
, it will be overridden by thetimeout
argument toresult()
.
-
add_done_callback
(fn)[source]¶ Add a callback to be executed when the operation is complete.
If the operation is completed, the callback will be scheduled onto the event loop. Otherwise, the callback will be stored and invoked when the future is done.
- Parameters
fn (Callable[Future]) – The callback to execute when the operation is complete.
-
async
done
(retry=<google.api_core.retry_async.AsyncRetry object>)[source]¶ Checks to see if the operation is complete.
- Parameters
retry (google.api_core.retry.Retry) – (Optional) How to retry the RPC.
- Returns
True if the operation is complete, False otherwise.
- Return type
-
async
exception
(timeout=None)[source]¶ Get the exception from the operation.
- Parameters
timeout (int) – How long to wait for the operation to complete. If None, wait indefinitely.
- Returns
- The operation’s
error.
- Return type
Optional[google.api_core.GoogleAPICallError]
-
async
result
(timeout=None)[source]¶ Get the result of the operation.
- Parameters
timeout (int) – How long (in seconds) to wait for the operation to complete. If None, wait indefinitely.
- Returns
The Operation’s result.
- Return type
google.protobuf.Message
- Raises
google.api_core.GoogleAPICallError – If the operation errors or if the timeout is reached before the operation completes.