RequestController class
A RequestController manages the lifecycle of a request, or multiple requests.
Its primary purpose is to allow the proper cancellation of requests on demand. This is useful for cases where a request is no longer needed, but the response is still being awaited. Calling cancel on the controller allows the library to clean up any resources associated with the request, and to ensure that the response is never delivered.
It is perfectly valid to register one controller per request if individual control over each request is desired. If you intend to call cancel on a controller, ensure the controller is only registered on requests that are intended to be cancelled together.
Constructors
- RequestController({Duration? timeout, PartialTimeouts? partialTimeouts})
- Creates a new RequestController.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasLifecycleTimeouts → bool
-
Returns true if this controller has any timeouts specified for individual
parts of a request's lifecycle.
no setter
- hasTimeouts → bool
-
Returns true if this controller has any timeouts specified.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration?
-
The timeout for the entire round trip of a request before it is aborted.
final
Methods
-
cancel(
[String message = 'Request cancelled']) → void - Cancels/aborts all pending requests on this controller. This will cause all requests to throw a CancelledException.
-
getExistingTracker(
BaseRequest request) → ActiveRequestTracker? -
hasTimeoutForLifecycleState(
RequestLifecycleState state) → bool -
Returns true if a timeout is specified for the specified request
lifecycle
state
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
timeoutForLifecycleState(
RequestLifecycleState state) → Duration? -
Returns the timeout for the specified request lifecycle
state
if there is one specified, otherwise returns null. -
toString(
) → String -
A string representation of this object.
inherited
-
track(
BaseRequest request, {required bool isStreaming}) → ActiveRequestTracker - Tracks a request with this controller.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited