Skip to content

Commit c028368

Browse files
committed
Update RequestManager.request_async
1 parent 2b74166 commit c028368

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

web3/manager.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import uuid
32

43
from eth_utils import (
54
is_list_like,
@@ -8,9 +7,6 @@
87
from web3._utils.empty import (
98
empty,
109
)
11-
from web3._utils.threads import (
12-
spawn,
13-
)
1410
from web3.datastructures import (
1511
NamedElementOnion,
1612
)
@@ -102,6 +98,26 @@ def _make_request(self, method, params):
10298
)
10399
)
104100

101+
async def _make_async_request(self, method, params):
102+
"""TODO: Can this be made dry? Going for dumb solution for now.
103+
"""
104+
for provider in self.providers:
105+
request_func = provider.request_func(self.web3, tuple(self.middleware_stack))
106+
self.logger.debug("Making request. Method: %s", method)
107+
try:
108+
return await request_func(method, params)
109+
except CannotHandleRequest:
110+
continue
111+
else:
112+
raise UnhandledRequest(
113+
"No providers responded to the RPC request:\n"
114+
"method:{0}\n"
115+
"params:{1}\n".format(
116+
method,
117+
params,
118+
)
119+
)
120+
105121
def request_blocking(self, method, params):
106122
"""
107123
Make a synchronous request using the provider
@@ -113,14 +129,16 @@ def request_blocking(self, method, params):
113129

114130
return response['result']
115131

116-
def request_async(self, raw_method, raw_params):
117-
request_id = uuid.uuid4()
118-
self.pending_requests[request_id] = spawn(
119-
self.request_blocking,
120-
raw_method=raw_method,
121-
raw_params=raw_params,
122-
)
123-
return request_id
132+
async def request_async(self, method, params):
133+
"""Ok breaking change to public API?
134+
Maybe should be a new function "coro_request".
135+
"""
136+
response = await self._make_async_request(method, params)
137+
138+
if "error" in response:
139+
raise ValueError(response["error"])
140+
141+
return response['result']
124142

125143
def receive_blocking(self, request_id, timeout=None):
126144
try:

0 commit comments

Comments
 (0)