(self, future: Coroutine)
| 547 | ) |
| 548 | |
| 549 | async def _race_with_page_close(self, future: Coroutine) -> None: |
| 550 | fut = asyncio.create_task(future) |
| 551 | # Rewrite the user's stack to the new task which runs in the background. |
| 552 | setattr( |
| 553 | fut, |
| 554 | "__pw_stack__", |
| 555 | getattr(asyncio.current_task(self._loop), "__pw_stack__", inspect.stack(0)), |
| 556 | ) |
| 557 | target_closed_future = self.request._target_closed_future() |
| 558 | await asyncio.wait( |
| 559 | [fut, target_closed_future], |
| 560 | return_when=asyncio.FIRST_COMPLETED, |
| 561 | ) |
| 562 | if fut.done() and fut.exception(): |
| 563 | raise cast(BaseException, fut.exception()) |
| 564 | if target_closed_future.done(): |
| 565 | await asyncio.gather(fut, return_exceptions=True) |
| 566 | |
| 567 | |
| 568 | def _create_task_and_ignore_exception( |
no test coverage detected