Skip to content

Commit

Permalink
added CancellationToken to example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kfir Matityahu committed Dec 16, 2024
1 parent 3cfcb76 commit 7751860
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions chopper/example/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:chopper/chopper.dart';
import 'package:cancellation_token/cancellation_token.dart';

import 'definition.dart';

Future<void> main() async {
var token = CancellationToken();
final chopper = ChopperClient(
baseUrl: Uri.parse('http://localhost:8000'),
services: [
Expand All @@ -14,8 +16,19 @@ Future<void> main() async {

final myService = chopper.getService<MyService>();

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);
Expand Down

0 comments on commit 7751860

Please sign in to comment.