Attaches a callable that will be called when the future finishes. Args: fn: A callable that will be called with this future as its only argument when the future completes or is cancelled. The callable will always be called by a thread in the same
(self, fn)
| 406 | return self._result |
| 407 | |
| 408 | def add_done_callback(self, fn): |
| 409 | """Attaches a callable that will be called when the future finishes. |
| 410 | |
| 411 | Args: |
| 412 | fn: A callable that will be called with this future as its only |
| 413 | argument when the future completes or is cancelled. The callable |
| 414 | will always be called by a thread in the same process in which |
| 415 | it was added. If the future has already completed or been |
| 416 | cancelled then the callable will be called immediately. These |
| 417 | callables are called in the order that they were added. |
| 418 | """ |
| 419 | with self._condition: |
| 420 | if self._state not in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]: |
| 421 | self._done_callbacks.append(fn) |
| 422 | return |
| 423 | try: |
| 424 | fn(self) |
| 425 | except Exception: |
| 426 | LOGGER.exception('exception calling callback for %r', self) |
| 427 | |
| 428 | def result(self, timeout=None): |
| 429 | """Return the result of the call that the future represents. |