I realized that using UV_RUN_DEFALUT is suitable for apps that doesn't care about performance too much. Just do the work 🤷
The meaning of work is a definition by your self. For example handling request can be a work, or updating some internal states of app....
I defined my work flow like this:
1. reading callback just place the arrived data in buffer. Nothing else.
2. When the loop ran just once, in an idle function, retrieve the buffers and sessions and handle the request.
So, Work for me is handling request, and when there is no request, there is no work to do.
I implement loop running like this:
if(sessions_count=0)
uv_run(UV_RUN_DEFALUT);
else {
// Start the idle handle and...
uv_run(UV_RUN_NOWAIT);
}
I know that it is complicated 🤣, you can use prepare handle as well. Loop does waiting when there is a prepare handle in it's list.