Wait for a connection to be set and return it. Raise an exception if the wait times out or if fail() is called.
(self, timeout: float)
| 953 | self._cond = ACondition() |
| 954 | |
| 955 | async def wait(self, timeout: float) -> ACT: |
| 956 | """Wait for a connection to be set and return it. |
| 957 | |
| 958 | Raise an exception if the wait times out or if fail() is called. |
| 959 | """ |
| 960 | async with self._cond: |
| 961 | if not (self.conn or self.error): |
| 962 | try: |
| 963 | if not await self._cond.wait_timeout(timeout): |
| 964 | self.error = PoolTimeout( |
| 965 | f"couldn't get a connection after {timeout:.2f} sec" |
| 966 | ) |
| 967 | except CLIENT_EXCEPTIONS as ex: |
| 968 | self.error = ex |
| 969 | |
| 970 | if self.error: |
| 971 | raise self.error |
| 972 | else: |
| 973 | assert self.conn |
| 974 | return self.conn |
| 975 | |
| 976 | async def set(self, conn: ACT) -> bool: |
| 977 | """Signal the client waiting that a connection is ready. |
no test coverage detected