Skip to content

Periodic function execution? #1332

Answered by Jacob-Burckhardt
epsilon-0 asked this question in Q&A
Discussion options

You must be logged in to vote

This calls send every 1000 milliseconds and follows the requirements of the library for thread-safe code:

#include "App.h"
   
using namespace std;

struct PerSocketData {};

uWS::WebSocket<false, true, PerSocketData> *gws=nullptr;
    
int main() {
   auto loop = uWS::Loop::get();

   struct us_timer_t *delayTimer = us_create_timer((struct us_loop_t *) loop, 0, 0);

   us_timer_set(delayTimer, [](struct us_timer_t *) {
                               if (gws) {
                                  cout << "calling send" << endl;
                                  gws->send("from server", uWS::OpCode::TEXT);
                               }
                            }, 1000, 1000);
   
   uW…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@epsilon-0
Comment options

Comment options

You must be logged in to vote
6 replies
@epsilon-0
Comment options

@alexxmanea
Comment options

@ghost
Comment options

@alexxmanea
Comment options

@ghost
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants