user1995781
user1995781

Reputation: 19463

What is $http timeout mean?

When using $http we can set the timeout for it and it will look something like this:

$http.get(url,{timeout: 5000}).success(function(data){});

What is that timeout mean? Is it mean the connection (data download) must be completed within the timeout period? Or it is mean the delay time to receive respond from the server? What would be the best general minimal timeout setting for mobile connection?

Upvotes: 1

Views: 655

Answers (2)

jfriend00
jfriend00

Reputation: 707736

If the http request does not complete within the specified timeout time, then an error will be triggered.

So, this is kind of like saying the following to the $http.get() function:

  1. I'd like you to fetch me this URL and get me the data
  2. If you do that successfully, then call my .success() handler and give me the data.
  3. If the request takes longer than 5000ms to finish, then rather than continue to wait, trigger a timeout error.

FYI, it looks to me like AngularJS has converted to using standard promise syntax, so you should probably be doing this:

$http.get(url,{timeout: 5000}).then(function(data){
    // successfully received the data here
}, function(err) {
    // some sort of error here (could be a timeout error)
});

What is that timeout mean? Is it mean the connection (data download) must be completed within the timeout period?

Yes. If not completed within that time period, it will return an error instead. This avoids waiting a long time for a request.

Or it is mean the delay time to receive respond from the server?

No, it is not a delay time.

What would be the best general minimal timeout setting for mobile connection?

This is hard to say without more specifics. Lots of different things might drive what you would set this to. Sometimes, there is no harm in letting the timeout be a fairly long value (say 120 seconds) in case the server or some mobile link happens to be particularly slow some day and you want to give it as much chance as possible to succeed in those circumstances. In other cases (depending upon the particular user interaction), the user is going to give up anyway if the response time is more than 5 seconds so there may be no value in waiting longer than that for a result the user will have already abandoned.

Upvotes: 3

Lucas Rodriguez
Lucas Rodriguez

Reputation: 1203

timeout – {number|Promise} – timeout in milliseconds, or promise that should abort the request when resolved. Source

Timeout means "perform an action after X time", in JS anyway.

Upvotes: 0

Related Questions