refactor: null safe http_timeout

This commit is contained in:
Lukas Lihotzki 2021-09-20 10:29:07 +02:00 committed by Krille Fear
parent b3c6b5f637
commit f491cfacc2
1 changed files with 3 additions and 4 deletions

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2021 Famedly GmbH
@ -27,7 +26,7 @@ import '../../matrix.dart';
/// In contrast, streamTotalTimeout fails if the stream isn't completed
/// until timeoutFuture.
Stream<T> streamTotalTimeout<T>(
Stream<T> stream, Future<Null> timeoutFuture) async* {
Stream<T> stream, Future<Never> timeoutFuture) async* {
final si = StreamIterator(stream);
while (await Future.any([si.moveNext(), timeoutFuture])) {
yield si.current;
@ -58,7 +57,7 @@ abstract class TimeoutHttpClient extends http.BaseClient {
@override
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]);
return replaceStream(
response, streamTotalTimeout(response.stream, timeoutFuture));
@ -91,7 +90,7 @@ class VariableTimeoutHttpClient extends TimeoutHttpClient {
@override
Future<http.StreamedResponse> send(http.BaseRequest request,
{Duration timeout}) async {
{Duration? timeout}) async {
try {
final response = await super.send(request);
return replaceStream(response, (() async* {