Skip to content

Commit

Permalink
feat(protocol): Implement concurrent api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiWo committed Nov 30, 2023
1 parent f9cbd2f commit f286dff
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions duties/protocol/request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module for fetching data from a beacon client
"""

from asyncio import sleep
from asyncio import TaskGroup, sleep
from enum import Enum
from itertools import chain
from logging import getLogger
Expand Down Expand Up @@ -56,8 +56,12 @@ async def send_beacon_api_request(
program.NUMBER_OF_VALIDATORS_PER_REST_CALL,
)
]
for chunk in chunked_validators:
responses.append(await __send_request(endpoint, calldata_type, chunk))
async with TaskGroup() as taskgroup:
tasks = [
taskgroup.create_task(__send_request(endpoint, calldata_type, chunk))
for chunk in chunked_validators
]
responses = [task.result() for task in tasks]
else:
responses.append(await __send_request(endpoint, calldata_type, []))
return __convert_to_raw_data_responses(responses, flatten)
Expand Down

0 comments on commit f286dff

Please sign in to comment.