1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+
1516import asyncio
1617from threading import Thread
1718from typing import Any , Callable , Coroutine , Mapping , Optional , TypeVar , Union
@@ -59,7 +60,7 @@ async def create_client():
5960
6061 # Ignoring type since we're already checking the existence of a loop above.
6162 self .__async_client = asyncio .run_coroutine_threadsafe (
62- create_client (), self .__class__ .__loop # type: ignore
63+ create_client (), self .__class__ .__loop
6364 ).result ()
6465
6566 def close (self ):
@@ -101,11 +102,10 @@ def load_tool(
101102 """
102103 coro = self .__async_client .load_tool (name , auth_token_getters , bound_params )
103104
104- # We have already created a new loop in the init method in case it does not already exist
105- async_tool = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
106-
107105 if not self .__loop or not self .__thread :
108106 raise ValueError ("Background loop or thread cannot be None." )
107+
108+ async_tool = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result ()
109109 return ToolboxSyncTool (async_tool , self .__loop , self .__thread )
110110
111111 def load_toolset (
@@ -130,11 +130,10 @@ def load_toolset(
130130 """
131131 coro = self .__async_client .load_toolset (name , auth_token_getters , bound_params )
132132
133- # We have already created a new loop in the init method in case it does not already exist
134- async_tools = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
135-
136133 if not self .__loop or not self .__thread :
137134 raise ValueError ("Background loop or thread cannot be None." )
135+
136+ async_tools = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
138137 return [
139138 ToolboxSyncTool (async_tool , self .__loop , self .__thread )
140139 for async_tool in async_tools
0 commit comments