Recently I have been messing around with socket.io and found this interesting thing, that I can have emit function callback like this.
最近我一直在摆弄插座。io发现了一个有趣的东西,我可以像这样发出函数回调。
I start emitting on client side like this:
我开始在客户端发出这样的信号:
client.emit('eventToEmit', dataToEmit, function(error, message){
console.log(error);
console.log(message);
});
Then I can fire a callback from server-side like this:
然后我可以从服务器端发起回调,如下所示:
client.on('eventToEmit', function(data, callback){
console.log(data);
callback('error', 'message');
});
Everything works fine with no errors, but I am interested if doing something like this is appropriate since I have not seen anything similar in the documentation or any example so far.
一切工作正常,没有错误,但我对这样做是否合适感兴趣,因为到目前为止我还没有在文档或任何示例中看到类似的内容。
1 个解决方案
#1
30
It's perfectly legal.
这是完全合法的。
Those callbacks are called 'acknowledgement functions' and are summarily mentioned in the Wiki and described a bit more in detail on the NPM page ('Getting acknowledgements').
这些回调称为“确认函数”,在Wiki中有简要的介绍,在NPM页面上有更详细的描述(“获取确认”)。
EDIT: more recent documentation can be found here.
编辑:更多最新的文档可以在这里找到。
#1
30
It's perfectly legal.
这是完全合法的。
Those callbacks are called 'acknowledgement functions' and are summarily mentioned in the Wiki and described a bit more in detail on the NPM page ('Getting acknowledgements').
这些回调称为“确认函数”,在Wiki中有简要的介绍,在NPM页面上有更详细的描述(“获取确认”)。
EDIT: more recent documentation can be found here.
编辑:更多最新的文档可以在这里找到。