I have an event loop with its own dedicated thread, which has a suspending method for submitting events (suspends until the event is done dispatching). Let's say I'm hooking a pre-existing event loop into it, like a slack bot library. What should I consider when deciding which thread to submit events from (and therefore suspend)? Or should I submit events blocking from the main thread to keep everything in step with the event loop?
01/02/2020, 9:26 PM
Why are you suspending?
01/02/2020, 9:27 PM
@Dico listeners on the event loop can perform suspending operations, so the submission suspends as well to let all listeners complete their work
01/02/2020, 9:29 PM
Ok, dispatching in that sense
So with coroutines you have the ability to suspend a coroutine, which does not block a thread
Your event loop can have a single coroutine to guarantee a deterministic order of execution
But this constraint likely isn't necessary for communication with your app
So you should seek to launch a new coroutine to call your suspending dispatch function, whose implementation then posts the task and awaits listener completion
That way you dont block any activity
01/02/2020, 9:32 PM
Yeah, the event loop has a single coroutine that it runs. I guess, fundamentally, the question is: do I need my application to be in step with the event loop? Should I be suspending all other functionality while events are happening? To which the answers seems to be no
01/02/2020, 9:33 PM
This is my advice based on limited context at least