Skip to content

Commit

Permalink
feat: async it
Browse files Browse the repository at this point in the history
  • Loading branch information
kiraum committed May 17, 2024
1 parent 624510d commit fd60cd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions peering_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ async def main():

if args.all is True:
ixps = pgossip.load_yaml()
for ixp in ixps["ixps"]:
await pgossip.alice_host(ixp)
await pgossip.process_all_ixps_concurrently(ixps)

if options is False:
if len(sys.argv) == 1:
Expand Down
10 changes: 10 additions & 0 deletions pgossip/pgossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,13 @@ def load_yaml(self):
with open("pgossip/config.yaml", "r", encoding="utf8") as file:
data = yaml.load(file, Loader=yaml.FullLoader)
return data

async def process_all_ixps_concurrently(self, ixps):
"""
Asynchronously processes each IXP in the provided list concurrently by calling the alice_host method.
Args:
ixps (dict): A dictionary containing a list of IXPs under the key "ixps".
"""
tasks = [self.alice_host(ixp) for ixp in ixps["ixps"]]
await asyncio.gather(*tasks)

0 comments on commit fd60cd2

Please sign in to comment.