optimizing `on_dispatch`
mlite opened this issue · comments
Since we use multi-threads to handle each event, on_dispatch will create a new thread for any event. However, this is not optimal because some bots might have create threads for events that they don't care. We need to add a filter function, which should return true for events that a bot cares about and hence threads should be created. If the filter function returns false, no threads should be created.
How would the filtering be specified? Should I add a bool async
for each discord_set_on_xxx()
?
Ex:
// function signature
void
discord_set_on_ready(struct discord *client, message_create_cb *callback, bool async);
// function call
discord_set_on_ready(client, &on_ready, true); // will create new thread
Just a very simple filter like the following.
bool dispatch_filter(void *p_cxt)
``
So, if enabled it will make all dispatch events multithreaded, and the default behavior is have it singlethreaded?