I'm taking data from SIGNALR Hub with JavaScript client and works well, but I need simulate synchronous in some cases. For instance, taking parameters from a database, in a For Loop in my JavaScript client. Here is my javascript simplified
var results = []; // empty array to hold results
function test(){
var list = ['item 1','item 2,'item3',item 4']
for(var i = 0;i<list.length;i++){
// call to signalr hub
$.connection.hub.start().done(function(){
bip.server.getString( list[i] ).done(function(x){
results.push(x)});
});
// end call signalr hub
}
}
Obviusly, it doesn't work, function test() returns before hub server response populates the array results in done(). signalr returns a deferred object when calling bip.server.getSTring(...); but, server returns value on .done() that also is a deferred object.
My question is : How can I avoid javascript function exists before .done(...
does his job.