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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -