JaSHin
JaSHin

Reputation: 277

Dio: When cancel called. Requests isn't canceled

I have problem with canceling requests using Dio api client.

        final cancelToken = CancelToken();

        final request = host.request(path,
            data: data,
            queryParameters: query,
            options: Options(method: describeEnum(method)),
            cancelToken: cancelToken);

        final cancelableRequest = CancelableOperation.fromFuture(request, onCancel: () {
          cancelToken.cancel();
        });

When cancelToken.cancel(); is called I receive DioErrorType.CANCEL but request is not canceled (checked in Charles web proxy). I have tried throttling request but it always waits for response.

enter image description here

Upvotes: 2

Views: 7121

Answers (1)

Rohan Das
Rohan Das

Reputation: 556

Try to write this way to cancel Dio api calling

CancelToken cancelToken = CancelToken();

Request request = host.request(path,
  data: data,
  queryParameters: query,
  options: Options(method: describeEnum(method)),
  cancelToken: cancelToken);

// cancel the requests with "cancelled" message.
final cancelableRequest = CancelableOperation.fromFuture(request, onCancel: token.cancel("cancelled"));

Upvotes: 3

Related Questions