From e7b50e2392312afc8e09e0c145748057fd02a37f Mon Sep 17 00:00:00 2001 From: "Jason Smith (work)" Date: Thu, 15 Dec 2011 13:23:26 +0000 Subject: [PATCH] Clear the inactivity timer when dying. Closes #9 --- feed.js | 6 ++++++ test/issues.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/feed.js b/feed.js index 0e1e0e1..d37c66c 100644 --- a/feed.js +++ b/feed.js @@ -447,6 +447,12 @@ Feed.prototype.die = function(er) { // Warn code executing later that death has occured. self.dead = true + clearTimeout(self.inactivity_timer) + clearTimeout(self.pending.wait_timer) + + self.inactivity_timer = null + self.pending.wait_timer = null + var req = self.pending.request; self.pending.request = null; if(req) { diff --git a/test/issues.js b/test/issues.js index ea60443..5318369 100644 --- a/test/issues.js +++ b/test/issues.js @@ -48,6 +48,25 @@ test('Issue #8', function(t) { }) }) +test('Issue #9', function(t) { + var timeouts = timeout_tracker() + + follow({db:DB, inactivity_ms:30000}, function(er, change) { + if(change.seq == 1) + return // Let it run through once, just for fun. + + t.equal(change.seq, 2, 'The second change will be the last') + this.stop() + + setTimeout(check_inactivity_timer, 250) + function check_inactivity_timer() { + t.equal(timeouts().length, 0, 'No lingering timeouts after teardown: ' + tims(timeouts())) + timeouts().forEach(function(id) { clearTimeout(id) }) + t.end() + } + }) +}) + // // Utilities //