OLD | NEW |
1 library catch_errors; | 1 library catch_errors; |
2 | 2 |
3 import 'dart:async'; | 3 import 'dart:async'; |
4 | 4 |
5 Stream catchErrors(void body()) { | 5 Stream catchErrors(dynamic body()) { |
6 StreamController controller; | 6 StreamController controller; |
7 | 7 |
8 bool onError(e, st) { | 8 bool onError(e, st) { |
9 controller.add(e); | 9 controller.add(e); |
10 return true; | 10 return true; |
11 } | 11 } |
12 | 12 |
13 void onListen() { | 13 void onListen() { |
14 runZoned(body, onError: onError); | 14 runZoned(body, onError: onError); |
15 } | 15 } |
(...skipping 30 matching lines...) Expand all Loading... |
46 } | 46 } |
47 ZoneSpecification specification = new ZoneSpecification( | 47 ZoneSpecification specification = new ZoneSpecification( |
48 handleUncaughtError: errorHandler, scheduleMicrotask: asyncHandler); | 48 handleUncaughtError: errorHandler, scheduleMicrotask: asyncHandler); |
49 Zone zone = Zone.current.fork(specification: specification); | 49 Zone zone = Zone.current.fork(specification: specification); |
50 if (onError != null) { | 50 if (onError != null) { |
51 return zone.runGuarded(body); | 51 return zone.runGuarded(body); |
52 } else { | 52 } else { |
53 return zone.run(body); | 53 return zone.run(body); |
54 } | 54 } |
55 } | 55 } |
OLD | NEW |