Stop using asyncio.get_event_loop()

It is deprecated in newer Python versions.
Closes #4013.
This commit is contained in:
Lonami Exo
2023-01-11 21:02:29 +01:00
parent fb97a8aa87
commit 83bafa25e3
14 changed files with 82 additions and 99 deletions

View File

@@ -2088,7 +2088,7 @@ the scenes! This means you're now able to do both of the following:
async def main():
await client.send_message('me', 'Hello!')
asyncio.get_event_loop().run_until_complete(main())
asyncio.run(main())
# ...can be rewritten as:

View File

@@ -161,19 +161,17 @@ just get rid of ``telethon.sync`` and work inside an ``async def``:
await client.run_until_disconnected()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.run(main())
The ``telethon.sync`` magic module simply wraps every method behind:
The ``telethon.sync`` magic module essentially wraps every method behind:
.. code-block:: python
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.run(main())
So that you don't have to write it yourself every time. That's the
overhead you pay if you import it, and what you save if you don't.
With some other tricks, so that you don't have to write it yourself every time.
That's the overhead you pay if you import it, and what you save if you don't.
Learning
========