Skip to content

Commit

Permalink
feat: add timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Sep 15, 2023
1 parent 837a6a2 commit 6591330
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pywaze/route_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ def __init__(
self,
region="EU",
client: httpx.AsyncClient | None = None,
timeout: int = 10,
):
self.region = region
self.client = client
self.timeout = timeout
if self.client is None:
self.client = httpx.AsyncClient()
self.client = httpx.AsyncClient(timeout=timeout)

def already_coords(self, address: str) -> bool:
"""Already coordinates or address."""
Expand Down Expand Up @@ -91,7 +93,10 @@ async def address_to_coords(self, address: str) -> dict[str, Any]:

try:
response: httpx.Response = await self.client.get(
self.WAZE_URL + get_cord, params=url_options, headers=self.HEADERS
self.WAZE_URL + get_cord,
params=url_options,
headers=self.HEADERS,
timeout=self.timeout,
)
except httpx.TimeoutException as e:
raise WRCTimeoutError("Timeout getting coords for %s" % address) from e
Expand Down Expand Up @@ -154,7 +159,10 @@ async def get_route(

try:
response: httpx.Response = await self.client.get(
self.WAZE_URL + routing_server, params=url_options, headers=self.HEADERS
self.WAZE_URL + routing_server,
params=url_options,
headers=self.HEADERS,
timeout=self.timeout,
)
except httpx.TimeoutException as e:
raise WRCTimeoutError("Timeout getting route") from e
Expand Down

0 comments on commit 6591330

Please sign in to comment.