refactor: null safe http_timeout
This commit is contained in:
parent
b3c6b5f637
commit
f491cfacc2
|
|
@ -1,4 +1,3 @@
|
||||||
// @dart=2.9
|
|
||||||
/*
|
/*
|
||||||
* Famedly Matrix SDK
|
* Famedly Matrix SDK
|
||||||
* Copyright (C) 2021 Famedly GmbH
|
* Copyright (C) 2021 Famedly GmbH
|
||||||
|
|
@ -27,7 +26,7 @@ import '../../matrix.dart';
|
||||||
/// In contrast, streamTotalTimeout fails if the stream isn't completed
|
/// In contrast, streamTotalTimeout fails if the stream isn't completed
|
||||||
/// until timeoutFuture.
|
/// until timeoutFuture.
|
||||||
Stream<T> streamTotalTimeout<T>(
|
Stream<T> streamTotalTimeout<T>(
|
||||||
Stream<T> stream, Future<Null> timeoutFuture) async* {
|
Stream<T> stream, Future<Never> timeoutFuture) async* {
|
||||||
final si = StreamIterator(stream);
|
final si = StreamIterator(stream);
|
||||||
while (await Future.any([si.moveNext(), timeoutFuture])) {
|
while (await Future.any([si.moveNext(), timeoutFuture])) {
|
||||||
yield si.current;
|
yield si.current;
|
||||||
|
|
@ -58,7 +57,7 @@ abstract class TimeoutHttpClient extends http.BaseClient {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.StreamedResponse> send(http.BaseRequest request) async {
|
Future<http.StreamedResponse> send(http.BaseRequest request) async {
|
||||||
final timeoutFuture = Completer<Null>().future.timeout(timeout);
|
final timeoutFuture = Completer<Never>().future.timeout(timeout);
|
||||||
final response = await Future.any([inner.send(request), timeoutFuture]);
|
final response = await Future.any([inner.send(request), timeoutFuture]);
|
||||||
return replaceStream(
|
return replaceStream(
|
||||||
response, streamTotalTimeout(response.stream, timeoutFuture));
|
response, streamTotalTimeout(response.stream, timeoutFuture));
|
||||||
|
|
@ -91,7 +90,7 @@ class VariableTimeoutHttpClient extends TimeoutHttpClient {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.StreamedResponse> send(http.BaseRequest request,
|
Future<http.StreamedResponse> send(http.BaseRequest request,
|
||||||
{Duration timeout}) async {
|
{Duration? timeout}) async {
|
||||||
try {
|
try {
|
||||||
final response = await super.send(request);
|
final response = await super.send(request);
|
||||||
return replaceStream(response, (() async* {
|
return replaceStream(response, (() async* {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue