Set the given ``value`` as the `Future`'s result, if not cancelled. Avoids ``asyncio.InvalidStateError`` when calling ``set_result()`` on a cancelled `asyncio.Future`. .. versionadded:: 5.0
(
future: "Union[futures.Future[_T], Future[_T]]", value: _T
)
| 183 | |
| 184 | |
| 185 | def future_set_result_unless_cancelled( |
| 186 | future: "Union[futures.Future[_T], Future[_T]]", value: _T |
| 187 | ) -> None: |
| 188 | """Set the given ``value`` as the `Future`'s result, if not cancelled. |
| 189 | |
| 190 | Avoids ``asyncio.InvalidStateError`` when calling ``set_result()`` on |
| 191 | a cancelled `asyncio.Future`. |
| 192 | |
| 193 | .. versionadded:: 5.0 |
| 194 | """ |
| 195 | if not future.cancelled(): |
| 196 | future.set_result(value) |
| 197 | |
| 198 | |
| 199 | def future_set_exception_unless_cancelled( |
no outgoing calls