Closed nicoddemus closed 7 years ago
Btw, it should be possible to support both async
and normal functions without users having to do anything in special:
import aiohttp
def greet(message):
return f"Hello! {message.user}"
async def list_jobs(message):
async with aiohttp.ClientSession() as session:
response = await session.get('http://my-jenkins-server.org/api/list-jobs')
return 'All jobs: {}'.format(response.json()['jobs'])
patterns = [
Pattern('hello', greet),
Pattern('list jobs', list_jobs),
]
On our message handling loop, we can use inspect.isawaitable
to decide if we want to
await
on the handler or call it directly.
I want to learn more about AsyncIO, could I get this one?
Sure! I wonder now if we should make all handlers async. The user would just need to add await
, we can verify that he does and would make our implementation simpler. @rougeth what's your opinion here?
I believe the benefits of accepting both kind of handlers is greater them just async handlers. :)
Currently the handlers are not
async
functions. For simple interactions that is fine, but if the bot needs to do some I/O (accessing a database, consulting a website, etc) anasync
function would scale better.