0

We are making multiple HTTP requests using Angular:

$scope.GetTest1 = function () {
    $http.get("/test/GetTest1/").success(function (response) {
        $scope.res = response.aaData;
    });
} 

$scope.GetTest2 = function () {
    $http.get("/test/GetTest2/").success(function (response) { 
        $scope.res = response.aaData; 
    });
}

$scope.GetTest3 = function () {
    $http.get("/test/GetTest3/").success(function (response) { 
        $scope.res = response.aaData; 
    });
}

// This is called from an onclick of a button
$scope.LoadAll = function () {
    $scope.GetTest1();
    $scope.GetTest2();
    $scope.GetTest3();
}

We assumed that these were all called async, however, we have log4net enabled and we log the datetime when the 'gets' are received, and the times for all 3 are:

19:05:26

19:05:27

19:05:28

This was an unexpected surprise as we assumed the time would all be within 1 second. ie async.

Not sure if we're missing something,

Sorry, question is, how do we make these async calls?

11
  • @lin Sorry, just updated, basically, how do we make these async? Commented Mar 6, 2015 at 19:40
  • javascript is non-blocking and will not wait for a function to return. You need a promise chain for something like this. Commented Mar 6, 2015 at 19:41
  • Have you watched the requests in your browser's Network tab? Are you sure that your server isn't queuing the requests and handling them one at a time? Commented Mar 6, 2015 at 19:43
  • @JLRishe we're not expecting them to all complete with a second, however, we we're expecting the api to be hit 3 times pretty much within a second, however its not Commented Mar 6, 2015 at 19:45
  • 1
    @Simon Well, then it sounds like the server is queuing them. What kind of server is it? Do you know if it can serve up simultaneous requests? Commented Mar 6, 2015 at 20:00

1 Answer 1

1

I suppose that the reason of that perhaps is on the server side. I had almost the same result when server could serve only one request from one client. If response from server fulfils your $http requests in one second then that could be a problem. Please check your network statistics and if you see that they were called simultaneously but were served not immediately then it's server side problem.

You can easily track this on browser's devtools' timeline

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, just to confirm, your saying thats it possible that the server could only serve one http request at a time per client?
Looks like servers' pool is limited to 1 request. Hope these points will help you.
Hi, yes, finally resolved - the issue was actually due to the .net framework queuing the process per session... [SessionState(SessionStateBehavior.ReadOnly)] added to each controller resolved the issue, and now all requests are within ms of each other...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.