Files
sdk/tests/lib_2/async/catch_errors14_test.dart
T
Ben Konyi cdc7a16d8e Migrated test block 166 to Dart 2.0.
Bug:
Change-Id: Ib21357cf328ec25c1acc58c3b37a4a7bf2910fa1
Reviewed-on: https://dart-review.googlesource.com/4612
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2017-09-12 19:22:08 +00:00

48 lines
1.1 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
// Test that periodic Timers are handled correctly by `catchErrors`.
catchErrors(() {
int counter = 0;
new Timer.periodic(const Duration(milliseconds: 50), (timer) {
if (counter++ == 5) {
timer.cancel();
done.complete(true);
}
throw "error $counter";
});
}).listen((x) {
events.add(x);
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give time to complete the handlers.
Timer.run(() {
Expect.listEquals([
"main exit",
"error 1",
"error 2",
"error 3",
"error 4",
"error 5",
"error 6",
], events);
asyncEnd();
});
});
events.add("main exit");
}