Skip to content

Commit 28288c9

Browse files
committed
Clean up async socket compatibility code
1 parent be66e58 commit 28288c9

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

neo4j/_async_compat/network/bolt_socket.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def __init__(self, reader, protocol, writer): # , loop):
6969
self._timeout = None
7070

7171
async def _wait_for(self, fut):
72+
if self._timeout <= 0:
73+
# give the io-operation time for one loop cycle to do its thing
74+
await asyncio.sleep(0)
7275
try:
7376
return await asyncio.wait_for(fut, self._timeout)
7477
except asyncio.TimeoutError:
@@ -99,23 +102,10 @@ def settimeout(self, timeout):
99102
self._timeout = timeout
100103

101104
async def recv(self, n):
102-
# fut = self._loop.sock_recv(self._socket, n)
103-
104-
if self._timeout == 0:
105-
# TODO: is this ok? It's a nonblocking socket, after all...
106-
return self._socket.recv(n)
107105
fut = self._reader.read(n)
108106
return await self._wait_for(fut)
109107

110108
async def recv_into(self, buffer, nbytes):
111-
# if n < len(buff):
112-
# fut = self._loop.sock_recv_into(self._socket,
113-
# memoryview(buff[:n]))
114-
# else:
115-
# fut = self._loop.sock_recv_into(self._socket, buff)
116-
117-
if self._timeout == 0:
118-
return self._socket.recv_into(buffer, nbytes)
119109
# FIXME: not particularly memory or time efficient
120110
fut = self._reader.read(nbytes)
121111
res = await self._wait_for(fut)

0 commit comments

Comments
 (0)