Skip to content
This repository

_.throttle()'d function is never called when frequency is high #502

Closed
JulesAU opened this Issue March 07, 2012 · 3 comments

3 participants

JulesAU Jeremy Ashkenas cashlo
JulesAU

Test code (node.JS):

var underscore = require('underscore');

function y() {
    console.log('XXX');
}

var x = underscore.throttle(y, 100);

while (1) {
    x();
}

Expected: 'XXX' echoed every 100ms

Actual: XXX is echoed one time only.

In the inner loop in underscore.js, if (throttling) { is always true. So it seems to be a logic error rather than a problem with the event stack being saturated.

JulesAU

It seems to be use of debounce() which is preventing the throttling var from ever becoming false;

cashlo

the while loop is blocking any async function from running, you can try replace the while loop with
setInterval(x,0);
which will allow the throttle function to perform normally.

Jeremy Ashkenas
Owner

Yes -- a hard while loop will certainly block the main JS thread. This isn't meaningful for our implementation of throttle.

Jeremy Ashkenas jashkenas closed this April 02, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.