I know the recommended use case for Dojo. Deferrals should use dojo.when (def) or def.then () and provide a callback for when Deferment is allowed. However, sometimes I come across a scenario where I really need to wait for this Deferral to complete before continuing with the current thread. Here is an example (full example at http://jsfiddle.net/DG3Ax/2/ )
function getSomething() { var def = getSomeDeferred(); def.then(function(result) { dojo.place("<li>def.then() = " + result + "</li>", "output"); }); return def.gimmeTheResultNow(); } dojo.place("<li>getSomething() = " + getSomething() + "</li>", "output");
Obviously, Deferred.gimmeTheResultNow() does not exist, but the functionality I'm looking for. I have no control over the code that calls getSomething (), so I cannot get it to handle Deferred; he needs a real result.
I know that xhrGet () has a synchronization parameter that, I think, would do the job if it were an AJAX call, but that is not necessarily the case. Is there any other way to do this?
source share