cancel method
Cancels the HTTP request. If the CancelToken is not passed to the request method, this method never finishes.
Implementation
Future<void> cancel() async {
if (_state != CancelState.idle) {
return;
}
if (_refs.isNotEmpty) {
_state = CancelState.cancelling;
for (final ref in _refs) {
await rust.cancelRequest(token: ref);
}
} else {
// We need to wait for the ref to be set.
_state = CancelState.waitingForRef;
final ref = await _firstRef.future;
await rust.cancelRequest(token: ref);
}
_state = CancelState.done;
_refController.close();
_refs.clear();
}