Skip to content

Commit 9c88416

Browse files
committed
changes from comments on PR #3125
1 parent 0fb984c commit 9c88416

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

docs/internals.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ message and receive a response to that particular request,
201201
response *id* values coming back from the websocket connection. Any provider that does
202202
not adhere to the `JSON-RPC 2.0 specification <https://www.jsonrpc.org/specification>`_
203203
in this way will not work with ``PersistentConnectionProvider`` instances. The specifics
204-
of how the request processor handles this is outlined below.
204+
of how the request processor handles this are outlined below.
205205

206206
One-To-One Requests
207207
~~~~~~~~~~~~~~~~~~~
208208

209-
One-to-one requests can be summarized as any request that expects one response back.
210-
An example is using the ``eth`` module API to request the latest block number.
209+
One-to-one requests can be summarized as any request that expects only one response
210+
back. An example is using the ``eth`` module API to request the latest block number.
211211

212212
.. code-block:: python
213213
@@ -220,13 +220,13 @@ An example is using the ``eth`` module API to request the latest block number.
220220
221221
>>> asyncio.run(wsV2_one_to_one_example())
222222
223-
With websockets we have to call ``ws_send()`` and asynchronously receive responses via
224-
``ws.recv()``. In order to make the one-to-one request-to-response call work, we
225-
have to save the request information somewhere so that, when the response is received,
226-
we can match it to the original request that was made (the request with a matching *id*
227-
to the response that was received), and use that request information to process the
228-
response. Processing the response, in this case, means running it through the
229-
formatters and middlewares internal to the *web3.py* library.
223+
With websockets we have to call ``send()`` and asynchronously receive responses via
224+
``recv()``. In order to make the one-to-one request-to-response call work, we
225+
have to save the request information somewhere so that when the response is received
226+
we can match it to the original request that was made i.e. the request with a matching
227+
*id* to the response that was received). The stored request information is then used to
228+
process the response when it is received, piping it through the response formatters and
229+
middlewares internal to the *web3.py* library.
230230

231231
In order to store the request information, the ``RequestProcessor`` class has an
232232
internal ``RequestInformation`` cache. The ``RequestInformation`` class saves important
@@ -279,7 +279,7 @@ successful. For this reason, the original request is considered a one-to-one req
279279
so that a subscription *id* can be returned to the user on the same line, but the
280280
``listen_to_websocket()`` method on the
281281
:class:`~web3.providers.websocket.WebsocketConnection` class, the public API for
282-
interacting with the active websocket connection, is set up to receive many-to-one
282+
interacting with the active websocket connection, is set up to receive
283283
``eth_subscription`` responses over an asynchronous interator pattern.
284284

285285
.. code-block:: python

docs/providers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ Interacting with the Websocket Connection
397397
398398
This method is available for listening to websocket responses indefinitely.
399399
It is an asynchronous iterator that yields strictly one-to-many
400-
(e.g. eth_subscription responses) request-to-response responses from the
401-
websocket connection. To receive responses for 1-to-1 request-to-response
400+
(e.g. ``eth_subscription`` responses) request-to-response responses from the
401+
websocket connection. To receive responses for one-to-one request-to-response
402402
calls, use the standard API for making requests via the appropriate module
403403
(e.g. ``block_num = await w3.eth.block_number``)
404404

web3/manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,12 @@ async def _ws_recv_stream(self) -> AsyncGenerator[RPCResponse, None]:
369369
)
370370

371371
while True:
372+
# look in the cache for a response
372373
response = await self._request_processor.pop_raw_response(subscription=True)
373374
if response is not None:
374375
break
375376
else:
377+
# if no response in the cache, check the websocket connection
376378
if not self._provider._ws_lock.locked():
377379
async with self._provider._ws_lock:
378380
try:

web3/providers/websocket/websocket_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async def _match_response_id_to_request_id() -> RPCResponse:
213213
response, subscription=is_subscription
214214
)
215215

216-
# this is important to let asyncio run other tasksx
216+
# this is important to let asyncio run other tasks
217217
await asyncio.sleep(0.05)
218218

219219
try:

0 commit comments

Comments
 (0)