Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run hidle_t functionality in EventLoop #547

Closed
anuragvohraec opened this issue May 18, 2024 · 1 comment
Closed

How to run hidle_t functionality in EventLoop #547

anuragvohraec opened this issue May 18, 2024 · 1 comment

Comments

@anuragvohraec
Copy link

anuragvohraec commented May 18, 2024

Hi ithewei,

I was using hloop_t and hidle_t handle to manage events in my code.
However later I wanted to use multiple WebSocketClient in my code and found out that it accepts EvenLoopPtr to reuse the same event loop, which is what I wanted, so migrated my code to using EventLoopPtr instead of hloop_t.
To run something repeatedly, as like idle handle, I used something like this

eventLoop->postEvent([this](hv::Event* ev){
    this->runBusinessLogicInLoop(); //this again fires eventLoop->postEvent to continue looping
});

However I see using this apporach the CPU usage goes too high(shows 12% on my system), however simply using hidle_t does not have any such spike in CPU usage.
Is there similar functionality in EventLoopto go like run something when idle, and how to use it properly ?

I have checked the FAQ and Tutorial
However I am not able find relevant explanation that could have helped in my case.
And have also checked the test cases like EventLoop_test.cpp without success.
Can you please shed some light on how to go with this ?

Thank you in advance for this.

@anuragvohraec
Copy link
Author

Ok silly of me.
I completely replaced my Hloop with the EventLoop.
Now using the exsting hloop and passing it into my EventLoop and using it.
So I can keep using the idle handle and use the same event loop in my web sockets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant