forked from GitHub/dbot
this should clean up the timers properly
This commit is contained in:
parent
47d1f3ea31
commit
c3ffe8d729
@ -43,6 +43,7 @@ var reddit = function(dbot) {
|
|||||||
for(i=0;i<this.ints.length;i++) {
|
for(i=0;i<this.ints.length;i++) {
|
||||||
clearInterval(this.ints[i]);
|
clearInterval(this.ints[i]);
|
||||||
}
|
}
|
||||||
|
this.ints = [];
|
||||||
|
|
||||||
this.db.scan('reddit_feeds', function(channel) {
|
this.db.scan('reddit_feeds', function(channel) {
|
||||||
if(channel) {
|
if(channel) {
|
||||||
@ -53,7 +54,7 @@ var reddit = function(dbot) {
|
|||||||
checkTimes[channel.id] = {};
|
checkTimes[channel.id] = {};
|
||||||
_.each(channel.feeds, function(feed) {
|
_.each(channel.feeds, function(feed) {
|
||||||
checkTimes[channel.id][feed.subreddit] = Date.now();
|
checkTimes[channel.id][feed.subreddit] = Date.now();
|
||||||
this.ints.push(setInterval(function() {
|
var intervalId = setInterval(function() {
|
||||||
this.api.getNewPosts(feed.subreddit, checkTimes[channel.id][feed.subreddit], function(err, posts) {
|
this.api.getNewPosts(feed.subreddit, checkTimes[channel.id][feed.subreddit], function(err, posts) {
|
||||||
if(!err && posts.length > 0) {
|
if(!err && posts.length > 0) {
|
||||||
_.each(posts, function(post) {
|
_.each(posts, function(post) {
|
||||||
@ -71,7 +72,9 @@ var reddit = function(dbot) {
|
|||||||
checkTimes[channel.id][feed.subreddit] = Date.now();
|
checkTimes[channel.id][feed.subreddit] = Date.now();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this), feed.interval));
|
}.bind(this), feed.interval);
|
||||||
|
console.log(intervalId);
|
||||||
|
this.ints.push(intervalId);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user