Question

The libuv timer methods are documented here and provide a way for a Node.js addon to recieve a callback at regular intervals to perform arbitrary processing.

uv_timer_t timer;
uv_timer_init( uv_default_loop(), &timer);
uv_timer_start( &timer, callback, 0, interval );

Here callback is the timeout method, with prototype:

void callback( uv_timer_t *handle, int status );

How do I supply a context, preferably in the form of a void*, to the timer callback procedure?

Was it helpful?

Solution

You can supply a context by assigning a pointer to it to data member of the uv_timer_t structure, like so:

uv_timer_t timer;
timer.data = context;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top