Skip to main content

Library for Event-Driven architecture using asyncio.

Project description

py_ver issues

pypi_ver pypi_license pypi_package pypi_status

discord

Chronous is a asynchronous python library designed to make asynchronous event-driven architectures on discord.py

[Example]

class SampleArchitecture(BaseArchitecture):

    def __init__(self) -> None:
        super(SampleArchitecture, self).__init__(name="sample")

        # Registering events
        self.registerEvent(event=Setup())
        self.registerEvent(event=Init())
        self.registerEvent(event=Start())
        self.registerEvent(event=Close())

    def run(self) -> None:
        # Registering default lifecycle events
        # Start the game.
        print("Starting process...")
        asyncio.run(self.process())

    async def process(self) -> NoReturn:
        await self.dispatch("setup")
        await self.dispatch("init")
        print('='*20)
        await self.dispatch("start", datetime.datetime.now())
        index: int = 0
        while index < 10:
            print("Looping!")
            index += 1
        await self.dispatch("close")
        print('='*20)


sample = SampleArchitecture()


# Multiple listener sample
@sample.listen()
async def setup(ec: EventContext):
    print("{ec.name} phase - listener 1".format(ec=ec))


@sample.listen()
async def setup(ec: EventContext):
    print("{ec.name} phase - listener 2".format(ec=ec))


# EventContext  sample
@sample.listen()
async def init(ec: EventContext):
    print("Initialization phase")
    print("Event : {event}".format(event=ec.event))


# Additional arguments sample
@sample.listen()
async def start(ec: EventContext, time: datetime):
    print("Starting process...")
    print("Starting at : {time}".format(time=time))


# Exception sample
@sample.listen()
async def close(ec: EventContext):
    print("Closing process...")
    print(f"Make an error : {1/0}")

sample.run()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

chronous-1.2.0-py3-none-any.whl (8.5 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