View Full Version : turn asynch callbacks into synchronous flow?

07-16-2009, 08:03 AM
Hi all,
I need to do something unusual. Say a user is browsing my site, and before they navigate away, I need to perform some actions like logging them out, for which they would need some data from the server. On onunload, a SJAX request (AJAX with that parameter as false) is issued, code flow hangs, and when the result comes in, code flow resumes and does what it needs to. If AJAX were used, the script would unload and never get the callback.
Ok. So that's what I want. The problem is that I'm dealing with something other than an XMLHttpRequest object, and I can't simply supply a false parameter to the request function. I'm looking for some way to wrap an asynchronous routine of this object into a synchronous one. If call var result = myobject.get(data_to_send), code flow here hangs WHILE myobject calls this funky XMLHttpRequest-like object in asynchronous mode, waits for the callback, the callback is called, and myobject returns the result. So code stops synchronously outside of myobject.get, but waits asynchronously inside. Is that possible?

07-16-2009, 09:03 AM
this funky XMLHttpRequest-like object

I have to ask. Can you .zip up as an attachment to any reply the "funky X-like object"? I'd be curious to see.

07-17-2009, 01:54 AM
there's no object to zip unfortunately. I'm writing for a program which intercepts a name://blah, then calls a passed javascript function as a result. But once I POST or GET to name://blah, it's completely asynchronous until I receive the callback, and I need to to be synchronous. For simplicity I called it a funky XMLHttpRequest-like object :)