Skip to content
This repository

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

JulesAU opened this Issue March 07, 2012 · 3 comments

3 participants

JulesAU Jeremy Ashkenas cashlo

Test code (node.JS):

var underscore = require('underscore');

function y() {

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

while (1) {

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.


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


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

Jeremy Ashkenas

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.