VoxelBotUtils icon indicating copy to clipboard operation
VoxelBotUtils copied to clipboard

async cog setup

Open 6days9weeks opened this issue 3 years ago • 4 comments

To add support for async setups in a cog

async def setup(bot):
    n = Foo(bot)
    bot.add_cog(n)
    await n.initialize() # an async function which needs to be run on cog load, I know we can do bot.loop.create_task but this could be an good add-on

Could be useful while caching something or run some async code when it’s loaded

6days9weeks avatar Sep 17 '21 03:09 6days9weeks

I'm not against it, but that then means that teardown as well as load_extension and remove_extension need to also be async.

Maybe better (although more suited for VBU) would be a method that gets run when the cog is loaded? Some kind of async init.

I'm just throwing thoughts out there at the moment.

4Kaylum avatar Sep 17 '21 04:09 4Kaylum

I'm not against it, but that then means that teardown as well as load_extension and remove_extension need to also be async.

Maybe better (although more suited for VBU) would be a method that gets run when the cog is loaded? Some kind of async init.

I'm just throwing thoughts out there at the moment.

async init like we have startup_caching for db in cog? then its feasible for what I’m trying to do

6days9weeks avatar Sep 17 '21 04:09 6days9weeks

Wouldn't this break the drop in functionality of dpy cogs to vbu?

SpicyTakis avatar Oct 05 '21 23:10 SpicyTakis

Wouldn't this break the drop in functionality of dpy cogs to vbu?

As kae mentioned above, there might be some kind of async init instead of fully async setup and I don't think it'd break functionality of dpy cogs to vbu, there's async setup support for cogs on red-discordbot which I used to use sometime ago, you could do async, and normal setup as you do right now in it.

6days9weeks avatar Oct 06 '21 03:10 6days9weeks