I'm using uWebSockets in my C++ project, where I have my own custom event loop. It's a while loop, with a variable delay between each execution. It looks something like this:
while (true) {
std::this_thread::sleep_for (variableTime);
// Execute logic
}
I've previously been using another thread to execute logic, but I want to integrate the uWebSockets loop with my loop. Something like this:
#include <iostream>
#include <uWS/uWS.h>
using namespace std;
int main () {
uWS::Hub h;
h.onMessage([](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) {
ws->send(message, length, opCode);
});
if (h.listen(3000)) {
h.run();
}
while (true) {
std::this_thread::sleep_for (variableTime);
h.getMessages(); // <-- doesn't call `onMessage` until this is executed
// Execute logic
}
}
How would I go about doing this?