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