Skip to content

Commit

Permalink
Fixing debounce race-condition for timeouts
Browse files Browse the repository at this point in the history
Currently, the first `debounce()`, takes 10secs to run. The second `debounce` in a `setTimeout(debounce, 20)` takes 30secs total (10 for the `debounce` and 20secs for the `setTimeout`). With the unreliability of the `setTimeout` API, we end up having a race-condition, with the test failing (and occasionally passing). Pumping the timeout a few milliseconds solves this. I understand the two run parallel but I wouldn't rely on 5ms to know the difference.
  • Loading branch information
kdamball committed Jun 15, 2015
1 parent 22ac65d commit 90e7ccf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion debounce/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('debounce', function() {
setTimeout(function() {
assert.equal(called, 2);
done();
}, 35);
}, 45);
});

it('gets called with context', function(done) {
Expand Down

0 comments on commit 90e7ccf

Please sign in to comment.