How to disable async behaviour of RestClient

Hello,

While developing business console gadgets, we have noticed that, “_this.$scope.restClient” invoke() method is calling the webservices in async mode. How can we change this to sync mode ?.

Any help would be much appreciated.

Thansk and Regards,
Anish

You should use promises to logically make it synchronous,

Can you try something like this in your js function where you are using restClient to invoke an API,

var deferred = $q.defer();
_this.$scope.restClient.invoke(_this.$scope.URLS.JSON_DATA_GET,function(response,status,header,config){

    			   if(response){
                                        deferred.resolve(response);
    				   _this.$scope.gridOptions.data = response;
    			   }
    		   },function(response,status,headers,config){
                              deferred.reject({ message: "Something went wrong" });

    		   })

return deferred.promise;

here, “deferred” is a promise

1 Like

Dear Yashwanth ,

Could you please provide me sample for injecting the “$q” to controller. I tried the following way to inject $q, but it doesn’t work.

Tracker_7DF40093_EFFE_1036_BE32_1_Controller.$inject = [‘$scope’, ‘RestServiceProvider’, ‘EventBus’, ‘$log’, ‘config’,‘SharedService’,‘$q’];

Thanks and Regards,
Anish