void main(){
final cancelable = Cancelable();
int i = -1;
const int exceptionI = 0;
const int expectI = 9;
final timer = Timer.periodic(
const Duration(seconds: 1),
(timer) {
i = Random().nextInt(10);
},
);
try {
final res = await retry<int>(
() async {
print('$i');
if (i == exceptionI) {
throw Exception('exit');
}
if (i != expectI) {
throw Exception('retryable');
}
return i;
},
cancelable: cancelable,
cancel: () async {
timer.cancel();
},
able: (i, e) async {
if (e is! Exception || e.toString().contains('retryable') == false) {
throw e;
}
await Future.delayed(const Duration(seconds: 1));
},
);
print('$res');
} catch (e) {
print(e.toString());
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
make operation retryable.
License
neutronstarer/retryable_dart
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
make operation retryable.
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published