1
Fork 0
mirror of https://github.com/Steffo99/async-chain.git synced 2024-10-16 04:57:27 +00:00
A coroutine builder
Find a file
2021-06-14 16:34:23 +02:00
.idea First commit (0.1.0) 2021-06-13 20:42:02 +02:00
async_chain Add typing types 2021-06-14 04:39:43 +02:00
dist First commit (0.1.0) 2021-06-13 20:42:02 +02:00
.gitignore First commit (0.1.0) 2021-06-13 20:42:02 +02:00
async-chain.iml First commit (0.1.0) 2021-06-13 20:42:02 +02:00
LICENSE.txt First commit (0.1.0) 2021-06-13 20:42:02 +02:00
poetry.lock First commit (0.1.0) 2021-06-13 20:42:02 +02:00
pyproject.toml 🔧 Closes #3: Decrease Python version requirement to 3.6 2021-06-14 16:34:23 +02:00
README.md First commit (0.1.0) 2021-06-13 20:42:02 +02:00

async-chain

A coroutine builder

What?

Have you ever felt that the await syntax in Python was a bit clunky when chaining multiple methods together?

async def on_message(event):
    message = await event.get_message()
    author = await message.get_author()
    await author.send_message("Hello world!")

Or even worse:

async def on_message(event):
    (await (await (await event.get_message()).get_author()).send_message("Hello world!"))

async-chain is here to solve your problem!

async def on_message(event):
    await event.get_message().get_author().send_message("Hello world!")

How?

First, install async_chain with your favorite package manager:

$ pip install async_chain
$ pipenv install async_chain
$ poetry add async_chain

Then, add the @async_chain.method decorator to any async method you wish to make chainable, and the problem will be magically solved!

import async_chain

class MyEvent:
    @async_chain.method
    async def get_message(self):
        ...