Class Future (2.26.0)

Future()

This future object is returned from asychronous Pub/Sub publishing calls.

Calling result will resolve the future by returning the message ID, unless an error occurs.

Methods

Future

Future()

Initializes the future. Should not be called by clients.

add_done_callback

add_done_callback(
    callback: typing.Callable[[pubsub_v1.publisher.futures.Future], typing.Any]
) -> None

Attach a callable that will be called when the future finishes.

cancel

cancel() -> bool

Actions in Pub/Sub generally may not be canceled.

This method always returns False.

cancelled

cancelled() -> bool

Actions in Pub/Sub generally may not be canceled.

This method always returns False.

done

done()

Return True if the future was cancelled or finished executing.

exception

exception(timeout=None)

Return the exception raised by the call that the future represents.

Exceptions
Type Description
CancelledError If the future was cancelled.
TimeoutError If the future didn't finish executing before the given timeout.

result

result(timeout: typing.Optional[typing.Union[int, float]] = None) -> str

Return the message ID or raise an exception.

This blocks until the message has been published successfully and returns the message ID unless an exception is raised.

Parameter
Name Description
timeout typing.Union[int, float, NoneType]

The number of seconds before this call times out and raises TimeoutError.

Exceptions
Type Description
concurrent.futures.TimeoutError If the request times out.
Exception For undefined exceptions in the underlying call execution.

running

running() -> bool

Return True if the associated Pub/Sub action has not yet completed.

set_exception

set_exception(exception: typing.Optional[BaseException])

Set the result of the future as being the given exception.

Do not use this method, it should only be used internally by the library and its unit tests.

set_result

set_result(result: typing.Any)

Set the return value of work associated with the future.

Do not use this method, it should only be used internally by the library and its unit tests.

set_running_or_notify_cancel

set_running_or_notify_cancel() -> typing.NoReturn

Mark the future as running or process any cancel notifications.

Should only be used by Executor implementations and unit tests.

If the future has been cancelled (cancel() was called and returned True) then any threads waiting on the future completing (though calls to as_completed() or wait()) are notified and False is returned.

If the future was not cancelled then it is put in the running state (future calls to running() will return True) and True is returned.

This method should be called by Executor implementations before executing the work associated with this future. If this method returns False then the work should not be executed.

Exceptions
Type Description
RuntimeError if this method was already called or if set_result() or set_exception() was called.