| 96 | @pytest.fixture(scope="session") |
| 97 | def sync_gather(playwright: Playwright) -> Generator[Callable, None, None]: |
| 98 | def _sync_gather_impl(*actions: Callable) -> List[Any]: |
| 99 | g_self = greenlet.getcurrent() |
| 100 | results: Dict[Callable, Any] = {} |
| 101 | exceptions: List[Exception] = [] |
| 102 | |
| 103 | def action_wrapper(action: Callable) -> Callable: |
| 104 | def body() -> Any: |
| 105 | try: |
| 106 | results[action] = action() |
| 107 | except Exception as e: |
| 108 | results[action] = e |
| 109 | exceptions.append(e) |
| 110 | g_self.switch() |
| 111 | |
| 112 | return body |
| 113 | |
| 114 | async def task() -> None: |
| 115 | for action in actions: |
| 116 | g = greenlet(action_wrapper(action)) |
| 117 | g.switch() |
| 118 | |
| 119 | asyncio.create_task(task()) |
| 120 | |
| 121 | while len(results) < len(actions): |
| 122 | playwright._dispatcher_fiber.switch() |
| 123 | |
| 124 | if exceptions: |
| 125 | raise exceptions[0] |
| 126 | |
| 127 | return list(map(lambda action: results[action], actions)) |
| 128 | |
| 129 | yield _sync_gather_impl |
| 130 | |