portage.util.futures.extendedfutures module

class portage.util.futures.extendedfutures.ExtendedFuture(default_result=<object object>)

Bases: _asyncio.Future

Extended Future class adding convienince get and set operations with default result capabilities for unset result(). It also adds pass capability for duplicate set_result() calls.

_asyncio_future_blocking
_callbacks
_cancel_message
_exception
_log_traceback
_loop
_make_cancelled_error()

Create the CancelledError to raise if the Future is cancelled.

This should only be called once when handling a cancellation since it erases the context exception value.

_repr_info()
_result
_source_traceback
_state
add_done_callback()

Add a callback to be run when the future becomes done.

The callback is called with a single argument - the future object. If the future is already done when this is called, the callback is scheduled with call_soon.

cancel(msg=None)

Cancel the future and schedule callbacks.

If the future is already done or cancelled, return False. Otherwise, change the future’s state to cancelled, schedule the callbacks and return True.

cancelled()

Return True if the future was cancelled.

done()

Return True if the future is done.

Done means either that a result / exception are available, or that the future was cancelled.

exception()

Return the exception that was set on this future.

The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn’t done yet, raises InvalidStateError.

get(default=<object object>)

Convienience function to wrap result() but adds an optional default value to return rather than raise an InvalidStateError

Parameters

default – Optional override for the classwide default_result

Returns

the result data or the default value, raisies an exception if result is unset and no default is defined.

get_loop()

Return the event loop the Future is bound to.

remove_done_callback(fn, /)

Remove all instances of a callback from the “call when done” list.

Returns the number of callbacks removed.

result()

Return the result this future represents.

If the future has been cancelled, raises CancelledError. If the future’s result isn’t yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised.

set_exception(exception, /)

Mark the future done and set an exception.

If the future is already done when this method is called, raises InvalidStateError.

set_result(data, ignore_InvalidState=False)

Set the Future’s result to the data, optionally don’t raise an error for ‘InvalidStateError’ errors

Parameters

ignore_exception – Boolean