Skip to content

Conversation

@davfsa
Copy link
Member

@davfsa davfsa commented Nov 3, 2023

Summary

Allows the following use-case:

bot = hikari.GatewayBot("TOKEN")

@bot.listen()
async def connect_to_db(event: hikari.StartingEvent) -> None:
    try:
        database = Database.connect()
    except ConnectionFailureException:
        print("Failed to connect to database")
        await bot.close()

bot.run()

This would be the gist of the change as things currently stand, but I am not entirely happy with it. Ideally, we would want any interrupt or call to bot.close() (which should really resolve to the same thing internally to streamline the shutdown process, imo) at any point in time to immediately start the shutdown sequence.

When I get some time, I will play around with implementing the signal handling directly into the loop and (maybe) an event being set stops the loop and makes it continue to the shutdown phase rather than having to keep checking for the the event being set.

Any feedback on this is welcome!


Note for myself (probably wont be changed):
I also dislike how its a bit counter intuitive to check for None other than the event being set, but until CPython 3.11 we will not be able to change that since asyncio.Event tries to get the loop in __init__.

Checklist

  • I have run nox and all the pipelines have passed.
  • I have made unittests according to the code I have added/modified/deleted.

@davfsa davfsa added the enhancement New feature or request label Nov 3, 2023
@davfsa davfsa self-assigned this Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant