Skip to content

Commit f54a401

Browse files
authored
refactor!: use FutureOr to allow synchronous interceptors (#144)
Signed-off-by: Nikolas Rimikis <[email protected]> Co-authored-by: Nikolas Rimikis <[email protected]>
1 parent cd58d44 commit f54a401

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/models/interceptor_contract.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:http/http.dart';
24

35
///Interceptor interface to create custom Interceptor for http.
@@ -26,11 +28,11 @@ import 'package:http/http.dart';
2628
///}
2729
///```
2830
abstract class InterceptorContract {
29-
Future<bool> shouldInterceptRequest() async => true;
31+
FutureOr<bool> shouldInterceptRequest() => true;
3032

31-
Future<BaseRequest> interceptRequest({required BaseRequest request});
33+
FutureOr<BaseRequest> interceptRequest({required BaseRequest request});
3234

33-
Future<bool> shouldInterceptResponse() async => true;
35+
FutureOr<bool> shouldInterceptResponse() => true;
3436

35-
Future<BaseResponse> interceptResponse({required BaseResponse response});
37+
FutureOr<BaseResponse> interceptResponse({required BaseResponse response});
3638
}

lib/models/retry_policy.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ import 'package:http/http.dart';
3636
abstract class RetryPolicy {
3737
/// Defines whether the request should be retried when an Exception occurs
3838
/// while making said request to the server.
39-
Future<bool> shouldAttemptRetryOnException(
40-
Exception reason, BaseRequest request) async =>
39+
FutureOr<bool> shouldAttemptRetryOnException(
40+
Exception reason, BaseRequest request) =>
4141
false;
4242

4343
/// Defines whether the request should be retried after the request has
4444
/// received `response` from the server.
45-
Future<bool> shouldAttemptRetryOnResponse(BaseResponse response) async =>
46-
false;
45+
FutureOr<bool> shouldAttemptRetryOnResponse(BaseResponse response) => false;
4746

4847
/// Number of maximum request attempts that can be retried.
4948
final int maxRetryAttempts = 1;

0 commit comments

Comments
 (0)