track method
Tracks a request with this controller.
This method is called internally when a request is sent. It should not be called directly. A StateError will be thrown if the request is not bound to this controller.
If the request is already being tracked by this controller, the
existing ActiveRequestTracker
will be returned.
Implementation
@internal
ActiveRequestTracker track(BaseRequest request, {required bool isStreaming}) {
if (request.controller != this) {
throw StateError('Request is not bound to this controller');
}
if (_activeRequests.any((r) => r.request == request)) {
return _activeRequests.firstWhere((r) => r.request == request);
}
final activeRequest = ActiveRequestTracker(
request,
isStreaming: isStreaming,
timeout: timeout,
);
_activeRequests.add(activeRequest);
return activeRequest;
}