From f738cfa1a697eca739a3fff1762f3f94e834e3c4 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 5 Oct 2022 16:58:07 +0200 Subject: [PATCH] neon: Cleanup request manager --- .../neon/lib/src/utils/request_manager.dart | 91 +------------------ 1 file changed, 3 insertions(+), 88 deletions(-) diff --git a/packages/neon/lib/src/utils/request_manager.dart b/packages/neon/lib/src/utils/request_manager.dart index 71e94257..f69bc9e7 100644 --- a/packages/neon/lib/src/utils/request_manager.dart +++ b/packages/neon/lib/src/utils/request_manager.dart @@ -7,14 +7,6 @@ class RequestManager { final Cache? cache; - final bool _enablePrinting = false; - - void _print(final String input) { - if (_enablePrinting) { - debugPrint(input); - } - } - Stream> wrapWithoutCache( final Future Function() call, { final bool disableTimeout = false, @@ -36,68 +28,6 @@ class RequestManager { required final T? previousData, final bool disableTimeout = false, }) async* { - yield* _wrap( - clientID, - k, - (final s) => json.encode(serialize(s)), - (final d) => deserialize(json.decode(d)), - call, - unwrap: unwrap, - previousData: previousData, - disableTimeout: disableTimeout, - ); - } - - Stream> wrapBytes( - final String clientID, - final String k, - final Future Function() call, { - final bool preferCache = false, - final bool disableTimeout = false, - final Uint8List? previousData, - }) => - _wrap( - clientID, - k, - (final s) => base64.encode(s), - (final d) => base64.decode(d), - call, - preferCache: preferCache, - previousData: previousData, - disableTimeout: disableTimeout, - ); - - Stream> wrapString( - final String clientID, - final String k, - final Future Function() call, { - final bool preferCache = false, - final bool disableTimeout = false, - final String? previousData, - }) => - _wrap( - clientID, - k, - (final s) => s, - (final d) => d, - call, - preferCache: preferCache, - previousData: previousData, - disableTimeout: disableTimeout, - ); - Stream> _wrap( - final String clientID, - final String k, - final String Function(R) serialize, - final R Function(String) deserialize, - final Future Function() call, { - final bool preferCache = false, - final bool disableTimeout = false, - T Function(R)? unwrap, - final T? previousData, - }) async* { - unwrap ??= (final a) => a as T; - if (previousData != null) { yield ResultCached(previousData, loading: true); } else { @@ -106,35 +36,20 @@ class RequestManager { final key = '$clientID-$k'; - _print('[Request]: $k'); - if (cache != null && await cache!.has(key)) { - _print('[Cache]: $k'); - final s = unwrap(deserialize((await cache!.get(key))!)); - if (preferCache) { - yield Result.success(s); - return; - } else { - yield ResultCached(s, loading: true); - } + yield ResultCached(unwrap(deserialize(json.decode((await cache!.get(key))!))), loading: true); } try { final response = await _timeout(disableTimeout, call); - - final s = serialize(response); - _print('[Response]: $k'); - await cache?.set(key, s); - + await cache?.set(key, json.encode(serialize(response))); yield Result.success(unwrap(response)); } on Exception catch (e) { if (cache != null && await cache!.has(key)) { - _print('[Cache]: $k'); debugPrint(e.toString()); - yield ResultCached(unwrap(deserialize((await cache!.get(key))!)), error: e); + yield ResultCached(unwrap(deserialize(json.decode((await cache!.get(key))!))), error: e); return; } - _print('[Failure]: $k'); debugPrint(e.toString()); yield Result.error(e); }