1

I have an asynchronous for loop and I would like to break it with an if statement. However, I am getting the following error:

Task was destroyed but it is pending!
task: <Task pending name='Task-71' coro=<<async_generator_athrow without __name__>()>>

The code:

messages_iter = client.get_chat_history(config["chat_id"])

messages_list = []
message_count = 0
async for message in messages_iter: 
    if message_count == 5:
        break
     
     message_list.append(message)
     message_count += 1
BenMorel
  • 34,448
  • 50
  • 182
  • 322
ai-py
  • 177
  • 1
  • 7

0 Answers0