Ah, so I think I found a workaround: simply guarantee that the timeout is
always nonzero. Even if the callback takes enough time to run that the
timer needs to run again immediately, the nonzero timeout seems to
guarantee that uv_run will come up for air before running it. See attached.
On Fri, Aug 1, 2014 at 12:22 AM, William Ehlhardt <[email protected]
> wrote:
> On Friday, July 25, 2014 4:33:29 AM UTC-5, Saúl Ibarra Corretgé wrote:
>>
>> There are multiple opinions about how that should go. I for one would
>> get rid of the timer repeat functionality and leave it on the hands of
>> the user so you calculate the time you want. Anyway, you can calculate
>> how long your callback took to execute and use uv_timer_set_repeat to
>> modify it, or just call uv_timer_start with the new timeout.
>>
>
> I wound up taking the latter option, but I discovered a problem: if I set
> the timeout to 0, UV_RUN_ONCE gets stuck running my callback forever
> (instead of, in my example, an async_t on the same loop that's trying to
> shut the loop down). See attached program, which gets stuck busylooping
> forever instead of terminating.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "libuv" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/libuv/uaN1o4IAWW8/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>
--
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 <time.h>
#include <uv.h>
uv_timer_t timer;
void run(uv_timer_t* _unused, int status) {
uv_timer_stop(&timer);
uv_timer_start(&timer, run, 1, 0);
sleep(1);
}
void main() {
uv_loop_t* loop = uv_default_loop();
uv_timer_init(loop, &timer);
uv_timer_start(&timer, run, 0, 0);
uv_run(loop, UV_RUN_ONCE);
}