Mark this side ready and park until `close()` is called. Single-shot, like `JSONRPCDispatcher.run`: once it returns the dispatcher stays closed and cannot be restarted.
(
self,
on_request: OnRequest,
on_notify: OnNotify,
*,
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
)
| 153 | await self._peer._dispatch_notify(method, params) |
| 154 | |
| 155 | async def run( |
| 156 | self, |
| 157 | on_request: OnRequest, |
| 158 | on_notify: OnNotify, |
| 159 | *, |
| 160 | task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED, |
| 161 | ) -> None: |
| 162 | """Mark this side ready and park until `close()` is called. |
| 163 | |
| 164 | Single-shot, like `JSONRPCDispatcher.run`: once it returns the |
| 165 | dispatcher stays closed and cannot be restarted. |
| 166 | """ |
| 167 | try: |
| 168 | self._on_request = on_request |
| 169 | self._on_notify = on_notify |
| 170 | self._running = True |
| 171 | self._ready.set() |
| 172 | task_status.started() |
| 173 | await self._close_event.wait() |
| 174 | finally: |
| 175 | self._running = False |
| 176 | self._closed = True |
| 177 | # run() may end via cancellation without close() ever being |
| 178 | # called; setting the event wakes `_wait_ready` waiters so they |
| 179 | # observe the closed state instead of parking forever. |
| 180 | self._close_event.set() |
| 181 | |
| 182 | def close(self) -> None: |
| 183 | self._closed = True |