javascript - Socketio returning information -
i want exit out of function return have gotten information socket.io request. function this:
function getsession(key) { socket.emit('client_get_session', {key : key}); socket.on('server_send_session', function(data) { return data; }); }
it should return data when receiving function seems end before data comes trough. when run console.log() first show function ending, console log actual data.
how able avoid , return 'data'?
callbacks helpfull, promises too...
function getsession(key, cb){ socket.emit('client_get_session', {key : key}); socket.on('server_send_session', function(data) { if(!data) return console.error('beep error occured'); cb && cb(data); }); } getsession(123,function(resdata){ console.log('result',resdata); })
Comments
Post a Comment