Skip to content

Commit 333dace

Browse files
committed
chore: Simplify add_headers to make it sync in async client
1 parent 8c38950 commit 333dace

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

packages/toolbox-core/src/toolbox_core/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ async def load_toolset(
307307

308308
return tools
309309

310-
async def add_headers(
310+
def add_headers(
311311
self, headers: Mapping[str, Union[Callable, Coroutine, str]]
312312
) -> None:
313313
"""
314-
Asynchronously Add headers to be included in each request sent through this client.
314+
Add headers to be included in each request sent through this client.
315315
316316
Args:
317317
headers: Headers to include in each request sent through this client.

packages/toolbox-core/src/toolbox_core/sync_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def load_toolset(
144144
if not self.__loop or not self.__thread:
145145
raise ValueError("Background loop or thread cannot be None.")
146146

147-
async_tools = asyncio.run_coroutine_threadsafe(coro, self.__loop).result() # type: ignore
147+
async_tools = asyncio.run_coroutine_threadsafe(coro, self.__loop).result()
148148
return [
149149
ToolboxSyncTool(async_tool, self.__loop, self.__thread)
150150
for async_tool in async_tools
@@ -154,18 +154,15 @@ def add_headers(
154154
self, headers: Mapping[str, Union[Callable, Coroutine, str]]
155155
) -> None:
156156
"""
157-
Synchronously Add headers to be included in each request sent through this client.
157+
Add headers to be included in each request sent through this client.
158158
159159
Args:
160160
headers: Headers to include in each request sent through this client.
161161
162162
Raises:
163163
ValueError: If any of the headers are already registered in the client.
164164
"""
165-
coro = self.__async_client.add_headers(headers)
166-
167-
# We have already created a new loop in the init method in case it does not already exist
168-
asyncio.run_coroutine_threadsafe(coro, self.__loop).result() # type: ignore
165+
self.__async_client.add_headers(headers)
169166

170167
def __enter__(self):
171168
"""Enter the runtime context related to this client instance."""

0 commit comments

Comments
 (0)