3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-11 12:32:36 +01:00

fix race condition in getting flag stack

This commit is contained in:
reality 2015-07-07 17:45:12 +00:00
parent f7785c95a3
commit 024ee7913e

View File

@ -17,12 +17,13 @@ var atheme = function(dbot) {
} else { } else {
this.flagStack[server][channel] = { this.flagStack[server][channel] = {
'flags': {}, 'flags': {},
'callbacks': [ callback ] 'callbacks': [ callback ],
'timeout': null
}; };
} }
dbot.say(server, 'chanserv', 'FLAGS ' + channel); dbot.say(server, 'chanserv', 'FLAGS ' + channel);
setTimeout(function() { // Delete callback if no response this.flagStack[server][channel].timeout = setTimeout(function() { // Delete callback if no response
if(_.has(this.flagStack[server], channel)) { if(_.has(this.flagStack[server], channel)) {
_.each(this.flagStack[server][channel].callbacks, function(callback) { _.each(this.flagStack[server][channel].callbacks, function(callback) {
callback(true, null); callback(true, null);
@ -95,7 +96,7 @@ var atheme = function(dbot) {
delete allFlags[u]; delete allFlags[u];
} }
}); });
async.each(_.keys(hostMasks), function(hostMask, done) { async.each(_.keys(hostMasks), function(hostMask, done) {
this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) {
_.each(users, function(user) { _.each(users, function(user) {
allFlags[user] = hostMasks[hostMask]; allFlags[user] = hostMasks[hostMask];
@ -103,12 +104,12 @@ var atheme = function(dbot) {
done(); done();
}); });
}.bind(this), function() { }.bind(this), function() {
console.log('DONE'); _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) {
_.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { callback(null, this.flagStack[event.server][end[1]].flags);
callback(null, this.flagStack[event.server][end[1]].flags); }.bind(this));
}.bind(this)); clearTimeout(this.flagStack[event.server][end[1]].timeout);
delete this.flagStack[event.server][end[1]]; delete this.flagStack[event.server][end[1]];
}.bind(this)); }.bind(this));
} }
} }
} else if(event.user === 'HostServ') { } else if(event.user === 'HostServ') {