Я не знаю много об асинхронности, я пытался преобразовать циклы в asyn c для, но теперь работает только первый элемент генератора, остальные игнорируются. Что не так с этим кодом?
async def get_requests(self, data, request_type):
for x in data:
r = [
'subscribe_on_model',
{
'collection': None,
'id': None,
'recursive': ''
}
]
r[1]['collection'] = request_type
r[1]['id'] = x
yield r
async def get_results(self):
async with BaseWebsocket(self.uri) as ws:
await ws.receive()
sport_keys = list(self.sports.keys())
sport_values = list(self.sports.values())
bundle_requests = self.get_requests(sport_values, 'LineSport')
async for bundle_request in bundle_requests:
results = []
sport_name = sport_keys[sport_values.index(bundle_request[1]['id'])]
b_request = [bundle_request]
await ws.send(b_request)
b_response = await ws.receive()
bundle_ids = b_response[0][1].get('lineCountryIds')
if bundle_ids:
championship_requests = self.get_requests(bundle_ids, 'LineCountry')
async for championship_request in championship_requests:
c_request = [championship_request]
await ws.send(c_request)
c_response = await ws.receive()
championship_ids = c_response[0][1].get('lineChampionshipIds')
if championship_ids:
event_requests = self.get_requests(championship_ids, 'LineChampionship')