Skip to content
Permalink
Branch: master
Find file Copy path
duwen fix #161 deb3388 Feb 15, 2019
0 contributors

Users who have contributed to this file

47 lines (41 sloc) 1.1 KB
import 'dart:async';
import 'package:dio/dio.dart';
main() async {
var dio = new Dio();
// Token can be shared with different requests.
CancelToken token = new CancelToken();
// In one minute, we cancel!
new Timer(new Duration(milliseconds: 200), () {
token.cancel("cancelled");
});
// The follow three requests with the same token.
var url1 = "https://accounts.google.com";
var url2 = "https://www.facebook.com";
var url3 = "https://www.baidu.com";
dio
.get(url1, cancelToken: token)
.then((response) => print('${response.request.path}: succeed!'))
.catchError(
(e) {
if (CancelToken.isCancel(e)) {
print('$url1: $e');
}
},
);
dio
.get(url2, cancelToken: token)
.then((response) => print('${response.request.path}: succeed!'))
.catchError((e) {
if (CancelToken.isCancel(e)) {
print('$url2: $e');
}
});
dio
.get(url3, cancelToken: token)
.then((response) => print('${response.request.path}: succeed!'))
.catchError((e) {
if (CancelToken.isCancel(e)) {
print('$url3: $e');
}
});
}
You can’t perform that action at this time.