Skip to content

Commit

Permalink
Fasten transaction broadcast with asyncio.gather
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Jan 29, 2016
1 parent 4cfa07b commit 8f7c9d4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/sakia/core/net/api/bma/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,19 @@ async def broadcast(self, request, req_args={}, post_args={}):
logging.debug("Trying to connect to : " + node.pubkey)
conn_handler = node.endpoint.conn_handler()
req = request(conn_handler, **req_args)
try:
reply = await req.post(**post_args)
replies.append(reply)
except ValueError as e:
if '404' in str(e) or '400' in str(e):
raise
except (ClientError, gaierror):
pass
except asyncio.TimeoutError:
pass
reply = asyncio.ensure_future(req.post(**post_args))
replies.append(reply)
self._invalidate_cache(request)
else:
raise NoPeerAvailable("", len(nodes))
return tuple(replies)

try:
result = await asyncio.gather(*replies)
except ValueError as e:
if '404' in str(e) or '400' in str(e):
raise
except (ClientError, gaierror):
pass
except asyncio.TimeoutError:
pass
return tuple(result)

0 comments on commit 8f7c9d4

Please sign in to comment.