Open Avalander opened 4 years ago
A couple other things we need to consider:
init
function?@SavagePixie do you have any thoughts on this?
It seems to me that option C might be marginally more convenient, as all modules would then export the same regardless of what specific features they need. At least, that's what I'm leaning towards.
Regarding how to handle failures in module initialisation, starting without the offending module (and a warning note) might be preferable? At least there'd still be some functionality.
I'm also leaning more towards option C, the more I think about it. It feels a bit awkward that the commands and shutdown function are accessible before initialising the module.
I've been thinking how to handle commands that need to do some asynchronous initialization and maybe a module system could be a good thing to have in place for that. Plus, it would provide a standard way to group commands with related functionality.
A quick draft of the API for a module could look like this:
Option A
Only the
commands
property would be required,init
andshutdown
can be implemented only when we need to do some initialization and/or clean up.Option B
Another option is to have the function
init
return the list of commands. Than way, we could grab declient
,settings
and other things from there instead of having to send it as a third argument to the command. Then, the propertycommands
would only be required when the functioninit
is not implemented.Option C
Or we might as well have the module export a factory function that would do any required initialization and return/resolve a list of commands and potentially a shutdown function.