Skip to content

Instantly share code, notes, and snippets.

@Esya
Created July 9, 2013 00:03
Show Gist options
  • Save Esya/5953544 to your computer and use it in GitHub Desktop.
Save Esya/5953544 to your computer and use it in GitHub Desktop.
Recursive client disconnection for socket.io tests.
//Instead of having..
client.disconnect();
client2.disconnect();
client3.disconnect();
done();
//Top of file
function recursiveDisconnect(Clients, callback) {
Client = Clients.pop();
Client.on('disconnect',function() {
if(Clients.length > 0) recursiveDisconnect(Clients);
else {
callback();
}
});
Client.disconnect();
}
//In test
recursiveDisconnect([client,client2,client3],done);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment