node.js socket.io socket.set() undefined property

心不动则不痛 提交于 2019-12-11 19:49:00

问题


I have something like this. This is my Controller.

    new singleton('User', function(model){
    model.find({username:data.username, password:_pass}, function(err,user){
        if (user.length==1)
        {
            socket.set('taxiId',user[0].id);
            cb(true);
        }
        else
            cb(false);
    });
});

If I set socket property like socket.set('name',value, function(){cb});

I get undefined here

        auth.authentificate(data, socket, function(logged){
        if (logged)
        {
            logs.login(data,socket);
            console.log(socket.taxiId);
            socket.emit('authOk',{err:'Ziaden error'});
        }

I tried set it with this

socket.set('taxiId', user[0].id, function(){cb(true);});

But nothing happend

Otherwise if I set property as

socket.taxiId = user[0].id;

It works simply good.

But here is one problem in asynchrone coding. If one setter socket.taxiId = 1; is called second getter socket.taxiId; returning undefined.

来源:https://stackoverflow.com/questions/20941437/node-js-socket-io-socket-set-undefined-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!