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.
(self, fn, *, context=None)
| 224 | return self._exception |
| 225 | |
| 226 | def add_done_callback(self, fn, *, context=None): |
| 227 | """Add a callback to be run when the future becomes done. |
| 228 | |
| 229 | The callback is called with a single argument - the future object. If |
| 230 | the future is already done when this is called, the callback is |
| 231 | scheduled with call_soon. |
| 232 | """ |
| 233 | if self._state != _PENDING: |
| 234 | self._loop.call_soon(fn, self, context=context) |
| 235 | else: |
| 236 | if context is None: |
| 237 | context = contextvars.copy_context() |
| 238 | self._callbacks.append((fn, context)) |
| 239 | |
| 240 | # New method not in PEP 3148. |
| 241 |