resolvingPageLoader method
Page loader that asks resolve for the client on every read.
A read that fails is tried once more only if the connection changed underneath it — the resolver hands back a different client (the old transport dropped and a reconnect replaced it). A failure on a connection that is still the same one is the server's answer and is not masked.
Implementation
PageLoader resolvingPageLoader(
ClientResolver resolve, {
Map<String, dynamic> Function(Map<String, dynamic>)? transform,
}) {
return (String uri) async {
_logger.debug('Loading page', {'uri': uri});
final first = await resolve();
try {
return await _readPage(first, uri, transform);
} catch (_) {
final current = await resolve();
if (identical(current, first)) rethrow;
_logger.info('Page read retried on the reconnected client', {'uri': uri});
return _readPage(current, uri, transform);
}
};
}