CancelToken class
Token for cancelling network requests.
用于取消网络请求的令牌。
This class provides a mechanism to cancel ongoing network requests. When a request is cancelled, all registered callbacks will be notified.
此类提供了取消正在进行的网络请求的机制。 当请求被取消时,所有注册的回调都会被通知。
Example / 示例:
final cancelToken = CancelToken();
// Start a request with cancel token
// 使用取消令牌启动请求
RxNet.get()
.setPath("/data")
.setCancelToken(cancelToken)
.request();
// Cancel the request
// 取消请求
cancelToken.cancel("User cancelled");
See also / 另见:
- AdapterRequest.cancelToken for using cancel tokens in requests
- NetworkAdapter.cancel for adapter-level cancellation
author: ZhengZaiHong email:1096877329@qq.com date: 2026-04-23 11:17
Constructors
Properties
- cancelReason → String?
-
The reason for cancellation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCancelled → bool
-
Whether the request has been cancelled.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cancel(
[String? reason]) → void - Cancels the request.
-
clearCallbacks(
) → void - Clears all callbacks.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeCallback(
void callback(String?)) → void - Removes a cancellation callback.
-
reset(
) → void - Resets the cancellation state (for testing).
-
toString(
) → String -
A string representation of this object.
override
-
whenCancel(
void callback(String?)) → void - Adds a cancellation callback.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited