_This issue was originally filed by theburnin...@gmail.com_
What steps will clearly show the issue / need for enhancement?
What version of the product are you using? On what operating system?
Dart 1.5.1, http 0.11.1+1
Probably the best way to support this would be to add a separate http_timeout_client package that exposes an HttpTimeoutClient that wraps an existing client.
_This comment was originally written by theburnin...@gmail.com_
Is there any reason why timeout couldn't be added as an optional parameter to the existing clients? I think the usage pattern would be more obvious this way than having to first create a client, then create another (HttpTimeoutClient) to wrap around it before you do a HTTP request.
The http package is based on a composition model where each layer (that is, a class implementing http.Client) is very simple and has a well-defined purpose. This model makes it very easy to mix and match functionality, but one of the costs is that the API for a layer has to be very simple in order to keep them easy to implement. It would be bad if everyone implementing their own [http.Client] had to re-implement the timeout logic from scratch.
having to first create a client, then create another (HttpTimeoutClient) to wrap around it before you do a HTTP request.
The API wouldn't be that difficult. The constructor would look something like this:
HttpTimeoutClient([HttpClient inner])
: _inner = inner == null ? new HttpClient() : inner;
The user only needs to construct one client if they only care about one aspect of the client.
_This comment was originally written by theburning...@gmail.com_
Hi, thanks for the explanation, that makes a lot of sense.
Issue #10411 has been merged into this issue.
_This comment was originally written by @seaneagan_
Doesn't Future.timeout solve this pretty well already?
https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-async.Future#id_timeout
Example:
http.read('http://google.com')
.timeout(const Duration(seconds: 5))
.then(...);
_Marked this as being blocked by #22265._
This issue has been moved to dart-lang/http#21.
Most helpful comment
_This comment was originally written by @seaneagan_
Doesn't
Future.timeoutsolve this pretty well already?https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-async.Future#id_timeout
Example:
http.read('http://google.com')
.timeout(const Duration(seconds: 5))
.then(...);