cancel method

  1. @override
void cancel(
  1. CancelToken token
)
override

Cancels an ongoing request.

This method cancels a request that is currently in progress. The request is identified by the token parameter.

Parameters:

  • token: The cancel token associated with the request to cancel

After calling this method, the request will be aborted and an AdapterException with type AdapterExceptionType.cancel will be thrown.

Example:

final cancelToken = CancelToken();

// Start a request
final request = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/data',
  method: HttpMethod.get,
  cancelToken: cancelToken,
);

// Cancel the request
adapter.cancel(cancelToken);

Implementation

@override
void cancel(CancelToken token) {
  // 取消所有使用此 token 的请求
  token.cancel();
}