Adds the callback *fun* to the future so that it be invoked when the
    future completed. The future completes either when it has been completed
    after being started with the :meth:`start` method (independent of whether
    an error occurs or not) or when either :meth:`set_result` or
    :meth:`set_exception` is called.

    If the future is already complete, *fun* will be invoked directly.

    The function *fun* must accept the future as its sole argument.

def add_done_callback(self, fun):
    """
    Adds the callback *fun* to the future so that it be invoked when the
    future completed. The future completes either when it has been completed
    after being started with the :meth:`start` method (independent of whether
    an error occurs or not) or when either :meth:`set_result` or
    :meth:`set_exception` is called.

    If the future is already complete, *fun* will be invoked directly.

    The function *fun* must accept the future as its sole argument.
    """

    with self._lock:
      if self._completed:
        fun()
      else:
        self._done_callbacks.append(fun)