Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: tests/lib_strong/async/catch_errors.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 library catch_errors;
2
3 import 'dart:async';
4
5 Stream catchErrors(void body()) {
6 StreamController controller;
7
8 bool onError(e, st) {
9 controller.add(e);
10 return true;
11 }
12
13 void onListen() {
14 runZoned(body, onError: onError);
15 }
16
17 controller = new StreamController(onListen: onListen);
18 return controller.stream;
19 }
20
21 runZonedScheduleMicrotask(body(),
22 { void onScheduleMicrotask(void callback()),
23 Function onError }) {
24 if (onScheduleMicrotask == null) {
25 return runZoned(body, onError: onError);
26 }
27 HandleUncaughtErrorHandler errorHandler;
28 if (onError != null) {
29 errorHandler = (Zone self, ZoneDelegate parent, Zone zone,
30 error, StackTrace stackTrace) {
31 try {
32 return self.parent.runUnary(onError, error);
33 } catch(e, s) {
34 if (identical(e, error)) {
35 return parent.handleUncaughtError(zone, error, stackTrace);
36 } else {
37 return parent.handleUncaughtError(zone, e, s);
38 }
39 }
40 };
41 }
42 ScheduleMicrotaskHandler asyncHandler;
43 if (onScheduleMicrotask != null) {
44 asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) {
45 self.parent.runUnary(onScheduleMicrotask, () => zone.runGuarded(f));
46 };
47 }
48 ZoneSpecification specification =
49 new ZoneSpecification(handleUncaughtError: errorHandler,
50 scheduleMicrotask: asyncHandler);
51 Zone zone = Zone.current.fork(specification: specification);
52 if (onError != null) {
53 return zone.runGuarded(body);
54 } else {
55 return zone.run(body);
56 }
57 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/async_await_zones_test.dart ('k') | tests/lib_strong/async/catch_errors11_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698