Hi all,
uv_timer_t's run interval seems to schedule the next run for $interval ms
*after* the callback completes, instead of accounting for the callback run
time and scheduling the next wakeup for $callback_start_time + $interval.
For example, if I set the interval to 1000ms, and the callback takes 100ms
to run, the callback will actually get run every 1100ms by libuv. Is there
a way to make it run every 1000ms instead?
See attached program for a demonstration. I expect the time to print out
every 5s, but it prints out every 7s because of the 2s sleep() in the
callback.
-William
--
You received this message because you are subscribed to the Google Groups
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.
#include <stdio.h>
#include <time.h>
#include <uv.h>
uv_loop_t *loop;
uv_timer_t gc_req;
uv_timer_t fake_job_req;
void fake_job(uv_timer_t* timer, int status) {
printf("%ld\n", (long int) time(NULL));
sleep(2);
}
int main() {
loop = uv_default_loop();
// could actually be a TCP download or something
uv_timer_init(loop, &fake_job_req);
uv_timer_start(&fake_job_req, fake_job, 0, 5000);
return uv_run(loop, UV_RUN_DEFAULT);
}