title: How can I do for in loop in async function binded to Telethon?
body: <p>I want to get access to dialogs and messages in Telethon in my async def function binded to NewMessage event with pattern 'get_data'. Overall, binding works and I get 'hi' response in STDOUT, but for loop not I don't get 'hi2' response and later code is not executed. I'm not sure if I understand asynchrous theory, but we will see.</p>
  
  <p>I tried few asyncio functions (like sleep, wait), moving my client.start() from before to after event binding, doing function with for-in loops outside and calling it with await inside async def and nothing works.</p>
  
  <pre class="lang-py prettyprint-override"><code>client = TelegramClient('session', api_id, api_hash)
  client.start()
  
  print('1')
  @client.on(events.NewMessage(pattern='get_data'))
  async def get_data(event):
      await print('hi')
      print(client.iter_dialogs())
      for dialog in client.iter_dialogs():
          print('hi2')
          print(dialog.name)
  
          for message in client.iter_messages(dialog.id, reverse=True):
              entity = client.get_entity(message.sender_id)
              print('{0} {1}'.format(entity.first_name, entity.last_name), ':', message.text)
      await event.respond('Got data!')
  
  client.run_until_disconnected()
  </code></pre>
  
  <p>I want for-in loops to be executed without messing out, since I want to expand this code more. I want them to be executed in /correct/ manner - so, when I get_data will be called I will get them executed like normal program without doing asynchrously inside (so, this why I wanted do await).</p>
  
  <p>Maybe my attempts are fine but I am not using correctly Telethon?</p>