Unable to send millisecond timeout.

79 views
Skip to first unread message

Alan Gutierrez

unread,
Nov 4, 2012, 1:59:57 AM11/4/12
to nod...@googlegroups.com
This gist...

http://gist.github.com/4010472

...contains a program that executes a function every millisecond using
setInterval. It then uses setTimeout to executes a function every two
milliseconds, then every millisecond, then it invokes a function
repeatedly with a zero value (which is supposed to be reset to 1
according to the documentation.) Finally, it invokes a function
repeatedly using nextTick.

Using the high-resolution timer, the program samples the intervals and
prints them to standard out.

The setInterval function works as expected, invoking its callback at
millisecond intervals. With a value of 2, setTimeout will invoke its
callback after a two millisecond interval. With a value of 1 or 0,
setTimeout calls back its callback immediately, in about two
microseconds, a little bit faster than nextTick.

Is this correct? I'd expect that setTimeout would always wait for at
least a millisecond before invoking its callback.

--
Alan Gutierrez - @bigeasy

Jorge

unread,
Nov 4, 2012, 5:09:42 AM11/4/12
to nodejs
The setTimeout(ƒ,0) behaving as a nextTick(ƒ) is the proper behaviour
for a setTimeout(ƒ,0) with no clamping (the browsers clamp it to a
minimun of several ms, mainly due to a bug in jquery).

But, the setTimeout(ƒ,1) behaving as a setTimeout(ƒ,0) is *clearly* a
bug.

Node's timers have always been buggy -and still are- for example this:

setTimeout(a,10), setTimeout(b,10)

may fire a then b, or b then a, which is another bug.

Cheers,
--
Jorge.

Rick Waldron

unread,
Nov 4, 2012, 1:43:29 PM11/4/12
to nod...@googlegroups.com
On Sun, Nov 4, 2012 at 5:09 AM, Jorge <jorge%jorgecha...@gtempaccount.com> wrote:


On 4 nov, 07:00, Alan Gutierrez <a...@prettyrobots.com> wrote:
> This gist...
>
> http://gist.github.com/4010472
>
> ...contains a program that executes a function every millisecond using
> setInterval. It then uses setTimeout to executes a function every two
> milliseconds, then every millisecond, then it invokes a function
> repeatedly with a zero value (which is supposed to be reset to 1
> according to the documentation.) Finally, it invokes a function
> repeatedly using nextTick.
>
> Using the high-resolution timer, the program samples the intervals and
> prints them to standard out.
>
> The setInterval function works as expected, invoking its callback at
> millisecond intervals. With a value of 2, setTimeout will invoke its
> callback after a two millisecond interval. With a value of 1 or 0,
> setTimeout calls back its callback immediately, in about two
> microseconds, a little bit faster than nextTick.
>
> Is this correct? I'd expect that setTimeout would always wait for at
> least a millisecond before invoking its callback.

The setTimeout(ƒ,0) behaving as a nextTick(ƒ) is the proper behaviour
for a setTimeout(ƒ,0) with no clamping (the browsers clamp it to a
minimun of several ms, mainly due to a bug in jquery).

What "bug" in jQuery are you referring to? No browser vendor/implementor would make any such concessions.


Rick
 

But, the setTimeout(ƒ,1) behaving as a setTimeout(ƒ,0) is *clearly* a
bug.

Node's timers have always been buggy -and still are- for example this:

setTimeout(a,10), setTimeout(b,10)

may fire a then b, or b then a, which is another bug.

Cheers,
--
Jorge.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Alexey Kupershtokh

unread,
Nov 4, 2012, 11:13:58 PM11/4/12
to nod...@googlegroups.com, jorge%jorge...@gtempaccount.com
I think it's about this bug in node.js https://github.com/joyent/node/pull/4194
setTimeout(..., 1) can sometimes behave as process.nextTick.
Also setTimeout(..., 0) is the same to setTimeout(..., 1) because of this line: https://github.com/joyent/node/blob/v0.9.3/lib/timers.js#L175 and therefore can behave as nextTick too.

воскресенье, 4 ноября 2012 г., 17:09:42 UTC+7 пользователь Jorge написал:
Reply all
Reply to author
Forward
0 new messages