I'm just starting using domains in nodejs for error management.
There's something I cant understand when I use them with socket.io.
That's my example code:
io.sockets.on('connection', function cb1(socket){
socket.on('event', function cb2(data){
});
});
I started putting all my code in the "run" method
domain.run(function(){
io.sockets.on('connection', function cb1(socket){
socket.on('event', function cb2(data){
});
});
});
But if an error happens in cb1 or cb2 it is not handled!
Then I used the bind methon on che cb1
domain.run(function(){
io.sockets.on('connection', domain.bind(function cb1(socket){
socket.on('event', function cb2(data){
});
}));
});
But if an error happens in cb2 it is not handled!
My question is: do I have to put a single "bind" on every callback? In the server and in the required files?
When I started studied the domains all the tutorials define them like the best solution to handle your errors in one single point!
Am I missing something?
Edit: Yes, you have to bind every callback.
Have a look on this screencast, it explains this problem: Node Tuts Episode VIII - Handling Errors Using Domains (he starts talking about this from 13:45).
If I have understood it correctly, if you don't emit or throw errors inside the callbacks, you have to explicitly bind them with
.bindor.intercept. But in my own experience in callbacks this is not enough, and I have to bind every callback to the domain.