Rename private cleanup and error handlers to public

Renamed the internal _cleanup and _handleError functions to cleanup and handleError, respectively, and updated all references.
This commit is contained in:
Ankit Mahato
2025-06-29 06:45:46 +05:30
parent 9735ed655d
commit 51cfccb555

View File

@ -176,14 +176,14 @@ Future<Stream<(String?, Duration?, String?)?>> streamHttpRequest(
StreamSubscription<String?>? subscription; StreamSubscription<String?>? subscription;
final stopwatch = Stopwatch()..start(); final stopwatch = Stopwatch()..start();
_cleanup() async { cleanup() async {
stopwatch.stop(); stopwatch.stop();
httpClientManager.closeClient(requestId); httpClientManager.closeClient(requestId);
await Future.microtask(() {}); await Future.microtask(() {});
controller.close(); controller.close();
} }
Future<void> _handleError(dynamic error) async { Future<void> handleError(dynamic error) async {
await Future.microtask(() {}); await Future.microtask(() {});
if (httpClientManager.wasRequestCancelled(requestId)) { if (httpClientManager.wasRequestCancelled(requestId)) {
controller.add((null, null, kMsgRequestCancelled)); controller.add((null, null, kMsgRequestCancelled));
@ -191,7 +191,7 @@ Future<Stream<(String?, Duration?, String?)?>> streamHttpRequest(
} else { } else {
controller.add((null, null, error.toString())); controller.add((null, null, error.toString()));
} }
await _cleanup(); await cleanup();
} }
controller.onCancel = () async { controller.onCancel = () async {
@ -214,7 +214,7 @@ Future<Stream<(String?, Duration?, String?)?>> streamHttpRequest(
); );
if (uri == null) { if (uri == null) {
await _handleError(uriError ?? 'Invalid URL'); await handleError(uriError ?? 'Invalid URL');
return controller.stream; return controller.stream;
} }
@ -245,8 +245,8 @@ Future<Stream<(String?, Duration?, String?)?>> streamHttpRequest(
subscription = stream.listen( subscription = stream.listen(
(data) => controller.add((data, stopwatch.elapsed, null)), (data) => controller.add((data, stopwatch.elapsed, null)),
onDone: () => _cleanup(), onDone: () => cleanup(),
onError: _handleError, onError: handleError,
); );
return controller.stream; return controller.stream;
@ -282,13 +282,13 @@ Future<Stream<(String?, Duration?, String?)?>> streamHttpRequest(
controller.add((data, stopwatch.elapsed, null)); controller.add((data, stopwatch.elapsed, null));
} }
}, },
onDone: () => _cleanup(), onDone: () => cleanup(),
onError: _handleError, onError: handleError,
); );
return controller.stream; return controller.stream;
} catch (e) { } catch (e) {
await _handleError(e); await handleError(e);
return controller.stream; return controller.stream;
} }
} }