Skip to main content

A coroutine builder

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async-chain-0.1.2.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

async_chain-0.1.2-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page