Skip to content

Commit

Permalink
fix callback for node 0.6 (issue #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yssk22 committed Mar 23, 2013
1 parent 7b44643 commit bd8cfbb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ MockFluentdServer.prototype.listen = function(callback){

MockFluentdServer.prototype.close = function(callback){
var self = this;
this._server.close(function(){
callback();
});
if( process.version.match(/^v0\.6\./) ){ // 0.6.x does not support callback for server.close();
this._server.close();
(function waitForClose(){
if( Object.keys(self._clients).length > 0 ){
setTimeout(waitForClose, 100);
}else{
callback();
}
})();
}else{
this._server.close(function(){
callback();
});
}
for(var i in self._clients){
self._clients[i].destroy();
self._clients[i].end();
// self._clients[i].destroy();
}
};

Expand Down

0 comments on commit bd8cfbb

Please sign in to comment.