Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:math';
- var random = Random.secure();
- Future<int> rand() {
- return Future.delayed(new Duration(seconds: 1), () { return random.nextInt(200); });
- }
- Future<int> get() async {
- print("beginning to save");
- int n = await rand();
- if (n < 100) {
- throw "unlucky";
- }
- return n - 100;
- }
- Future<int> persevere() async {
- while(true) {
- try {
- return await get();
- } catch(e) {
- print('error ${e}, retrying');
- }
- }
- }
- void main() {
- persevere().then((int a) {
- print('ok ${a}');
- });
- print("after then");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement