1

Will it be possible for the Worklight Adapter to be called synchronously?

This is the client code I am using:

function GetAccount(){
   var acctresponse;

   //Adapter call to get accounts from Server
   //Registered Onsuccess and OnFailure
   onSuccess: function(response){acctresponse=response},
   onFailure: function(error){acctresponse=null;}

   //UI Code dependent on above acctresponse.

}

Being Client adapter synchronous, the UI code is executed before the response arrives.

Can anyone suggest what is the best approach to handle a situation like this?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56

2 Answers2

1

Request to adapter is issued using AJAX, which stands for Asynchronous JavaScript and XML. Therefore the answer is no since underlying transport layer is asynchronous.

Anton
  • 3,166
  • 1
  • 13
  • 12
1

As was stated above the adapter calls are by nature asynchronous - as are many of the javascript APIs used in web and mobile development. To ensure that the UI code is only executed after the adapter call complets you should invoke it from the onSuccess callback function.

  • in a well-designed architecture, the UI shouldn't be aside the Data integration Layer. With Worklight, the callback function requires to have UI with data. I tried to deport my code with requireJS, but it seems to have collisions with worklight js API :( – ptitjuju69 Feb 26 '14 at 11:51