Skip to content

Steffo99/async-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-chain

A coroutine builder

Links

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

Releases

No releases published

Sponsor this project

Languages