Skip to content

Commit 47b8570

Browse files
committed
chore: Simplify add_headers to make it sync in async client
1 parent d6f6d1e commit 47b8570

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
@@ -308,11 +308,11 @@ async def load_toolset(
308308

309309
return tools
310310

311-
async def add_headers(
311+
def add_headers(
312312
self, headers: Mapping[str, Union[Callable, Coroutine, str]]
313313
) -> None:
314314
"""
315-
Asynchronously Add headers to be included in each request sent through this client.
315+
Add headers to be included in each request sent through this client.
316316
317317
Args:
318318
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)