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
()[source]¶ Checks to see if the operation is complete.
- 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.