alexander-akhmetov / python-telegram

Python client for the Telegram's tdlib
MIT License
609 stars 123 forks source link

async/await syntax #93

Open Pegorino82 opened 4 years ago

Pegorino82 commented 4 years ago

is it possible to use async/await with the library? if it is, does any have examples of usage? it will be greate for me)

alexander-akhmetov commented 4 years ago

Hi,

No, the library officially doesn't support async/await syntax, you'll have to write a wrapper if you want to use it.

nicolas17 commented 4 years ago

After seeing this, I thought it should be possible to use async/await with tdlib. So I tried it and I managed to get a low-level async tdjson wrapper working; by low-level I mean: await tdlib.send_request({'@type': 'sendMessage', ...})

However, looking at the current API of python-telegram and how it's implemented, I don't think it would be possible to support async/await and keep compatibility with the existing API...

alexander-akhmetov commented 4 years ago

Probably, it should be possible to have both the current synchronous client and a new async API, and the synchronous client could be migrated to use the new async-await API under the hood

nicolas17 commented 4 years ago

This is what I wrote, in case it helps: https://gist.github.com/nicolas17/c8330da13512c9743a3da4b7c7688a3b