Skip to content

Commit

Permalink
feat(helper): Implement concurrent calls for fetching duties
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiWo committed Nov 30, 2023
1 parent f286dff commit 0e8f281
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions duties/helper/help.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Helper module
"""

from asyncio import Task, TaskGroup
from multiprocessing.shared_memory import SharedMemory
from typing import Callable, List

Expand Down Expand Up @@ -123,18 +124,12 @@ async def fetch_upcoming_validator_duties() -> List[ValidatorDuty]:
Returns:
List[ValidatorDuty]: Sorted list with all upcoming validator duties
"""
upcoming_attestation_duties = await fetch_upcoming_attestation_duties()
upcoming_sync_committee_duties = await fetch_upcoming_sync_committee_duties()
upcoming_proposing_duties = await fetch_upcoming_proposing_duties()
duties = [
duty
for duties in [
upcoming_attestation_duties,
upcoming_proposing_duties,
upcoming_sync_committee_duties,
]
for duty in duties.values()
]
async with TaskGroup() as taskgroup:
tasks: List[Task[dict[str, ValidatorDuty]]] = []
tasks.append(taskgroup.create_task(fetch_upcoming_attestation_duties()))
tasks.append(taskgroup.create_task(fetch_upcoming_sync_committee_duties()))
tasks.append(taskgroup.create_task(fetch_upcoming_proposing_duties()))
duties = [duty for task in tasks for duty in task.result().values()]
duties.sort(key=__sort_duties)
return duties

Expand Down

0 comments on commit 0e8f281

Please sign in to comment.