1
Fork 0
mirror of https://github.com/Steffo99/async-chain.git synced 2024-11-21 04:24:22 +00:00
A coroutine builder
Find a file
2024-05-20 01:13:39 +02:00
.idea First commit (0.1.0) 2021-06-13 20:42:02 +02:00
.media Update project metadata 2024-05-20 01:13:39 +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 ↪ Update poetry.lock 2021-06-14 16:37:30 +02:00
pyproject.toml ⬆ Bump version to 0.1.2 2021-06-14 16:34:58 +02:00
README.md Update project metadata 2024-05-20 01:13:39 +02:00

async-chain

A coroutine builder

PyPI

About

The problem

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!")

The solution

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):
        ...