lejard-h / chopper

Chopper is an http client generator using source_gen and inspired from Retrofit.
https://hadrien-lejard.gitbook.io/chopper
Other
714 stars 123 forks source link

:sparkles: add per-request timeout #604

Closed techouse closed 7 months ago

techouse commented 7 months ago

This PR adds a new timeout annotation

/// Set a timeout for the request
final Duration? timeout;

that can be used like

@Get(path: 'get_timeout', timeout: Duration(seconds: 42))
Future<Response<String>> getTimeoutTest();

and generates the following code

@override
Future<Response<String>> getTimeoutTest() {
  final Uri $url = Uri.parse('/test/get_timeout');
  final Request $request = Request(
    'GET',
    $url,
    client.baseUrl,
  );
  return client
      .send<String, String>($request)
      .timeout(const Duration(microseconds: 42000000));
}

Addresses #603 Addresses https://github.com/dart-lang/http/issues/1186

techouse commented 7 months ago

Codecov complaining .... as always.

@JEuler @Guldem @vladRudenua23 would you mind checking this PR 😇