我正在为我的网站编写一个node.js类似Facebook的聊天插件,并且我一直遇到服务器在一天后崩溃的问题。我认为问题是我的session.event.addListener阻塞了侦听器数组导致崩溃。这是我添加监听器的代码:
this.events.addListener('update', o_.bind(function(package) {
if(this.clear != 0){
delete this.sessions[this.clear];
break; //will this break stop a listener from being added?
}
var _package = package.toJSON();
if(package.type == 'status' && package.status == 'offline') {
var sids = Object.keys(this.sessions), sid, sess;
for(sid in this.sessions) {
sess = this.sessions[sid];
if(sess.data('username') == package.username) {
if(sess.listeners.length)
sess.send(200, {type: 'goodbye'});
delete this.sessions[sid];
break; //here too
}
}
}
}, this));
};
if语句中的中断是否允许不添加侦听器,因为我不确定它是否正常工作。 谢谢!