Hello everyone, I'm having trouble with getting around asynchronous model 
of node, I have this function
 function getstream() {

                           console.log('calling testAvail, Avail value is:' 
+ available);
                            testAvailability();
*                        console.log('Available:'+available);*
                        if (*available* || SelfSharing) {

// Do something
                                setDefaults();


                                return;
                            }
     }

which calls testAvailability() function defined as

    function testAvailability()
    {
        console.log('entered test');
        var stat;
        var socket = io.connect('http://somedomain.com');
        socket.on('error', function() {

            console.log('There was an error at server end please try 
again');
//            chrome.runtime.reload();

            setTimeout(chrome.runtime.reload(),3000);
            //here i change options
            //socket = io.connect(host, options);
        });
        socket.emit('available');
        socket.on('available', function (status) {
            console.log('got status from server which is:'+ status);
          *  available=status;*
            console.log("inside the socket.on"+available);
            console.log('leaving test, do you see any got status above?');
        });

    }


Now in this first function I need the *available *variable's value but due 
to async nature, my first function continues without getting the value of 
*available 
*could someone please suggest some work around? code would help.
Thanks

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/0527bae0-e99c-4db0-9fed-5962c8461743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to