diff --git a/chopper/example/main.dart b/chopper/example/main.dart index 76a1112e..4224f227 100644 --- a/chopper/example/main.dart +++ b/chopper/example/main.dart @@ -1,8 +1,10 @@ import 'package:chopper/chopper.dart'; +import 'package:cancellation_token/cancellation_token.dart'; import 'definition.dart'; Future main() async { + var token = CancellationToken(); final chopper = ChopperClient( baseUrl: Uri.parse('http://localhost:8000'), services: [ @@ -14,8 +16,19 @@ Future main() async { final myService = chopper.getService(); - final response = await myService.getMapResource('1'); - print(response.body); + + Future.delayed(Duration(seconds: 2), () { + token.cancel(); + }); + + try { + final response = await myService.getMapResource('1'); + print(response.body); + } + on CancelledException { + print('cancelled by user!'); + } + final list = await myService.getListResources(); print(list.body);