in reply to Re: missing second of time
in thread missing second of time

Don't sleep FOR one second, sleep until the NEXT second.

Thanks for the lightbulb. I see no error since doing it that way. I wonder if the perldoc for sleep should add something like:

Maybe it's already a FAQ? I don't know. Thank you!

Replies are listed 'Best First'.
Re^3: missing second of time
by LanX (Saint) on Jan 25, 2020 at 23:11 UTC

    You are missing the conceptual loophole here.

    > print something();

    So what if something() takes longer than a second?

    Your sleep would just skip the missed steps till the following interval.

    The clean approach would be to include an exception handling.

    Apart from this could the OS be too busy to return in time, that's why sleep only guaranties minimal time.

    See Re: missing second of time

    > I wonder if the perldoc for sleep should add ...

    All these conditions might not be true in your case, but how do you want to include the general case in the docs???

    I think this use cases are best covered in a dedicated module.

    Update

    Might be interesting to compare how setInterval() in JS is handling those cases.

    Update

    From what I read after searching JS setInterval long running function it seems that delayed calls are queued to be executed later, and this without raising an exception. ... Ugly.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice