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

Unified Diff: sdk/lib/async/zone.dart

Issue 16801008: catchErrors and waitForCompletion now based on runZonedExperimental. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Some tests. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/async/catch_errors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/zone.dart
diff --git a/sdk/lib/async/zone.dart b/sdk/lib/async/zone.dart
index 58635ff529d1f02b7126f6559dc5c03bc4c5e71b..f49c65b6ab2fe1c294fb7a89aaf3ab30368b0ffd 100644
--- a/sdk/lib/async/zone.dart
+++ b/sdk/lib/async/zone.dart
@@ -237,13 +237,16 @@ class _ZoneBase implements _Zone {
// (probably) in the same zone and have an _openCallbacks > 0.
bool oldIsExecuting = _isExecutingCallback;
_isExecutingCallback = true;
+ // TODO(11244): remove second try when VM bug is fixed.
Lasse Reichstein Nielsen 2013/06/13 12:10:08 Bug has been marked as duplicate of 430, so renumb
floitsch 2013/06/13 14:38:55 Done.
try {
- return fun();
- } catch(e, s) {
- if (handleUncaught) {
- handleUncaughtError(_asyncError(e, s));
- } else {
- rethrow;
+ try {
+ return fun();
+ } catch(e, s) {
+ if (handleUncaught) {
+ handleUncaughtError(_asyncError(e, s));
+ } else {
+ rethrow;
+ }
}
} finally {
_isExecutingCallback = oldIsExecuting;
@@ -258,14 +261,14 @@ class _ZoneBase implements _Zone {
* Uncaught errors are given to [handleUncaughtError].
*/
_runGuarded(void fun()) {
- _runInZone(fun, true);
+ return _runInZone(fun, true);
}
/**
* Runs the function but doesn't catch uncaught errors.
*/
_runUnguarded(void fun()) {
- _runInZone(fun, false);
+ return _runInZone(fun, false);
}
runAsync(void fun()) {
@@ -345,8 +348,8 @@ class _WaitForCompletionZone extends _ZoneBase {
* Runs the given function asynchronously. Executes the [_onDone] callback
* when the zone is done.
*/
- void runWaitForCompletion(void fun()) {
- this._runGuarded(fun);
+ runWaitForCompletion(void fun()) {
+ return this._runUnguarded(fun);
}
_dispose() {
@@ -375,6 +378,14 @@ class _CatchErrorsZone extends _WaitForCompletionZone {
if (!_handleError(error)) _parentZone.handleUncaughtError(error);
}
+ /**
+ * Runs the given function asynchronously. Executes the [_onDone] callback
+ * when the zone is done.
+ */
+ runWaitForCompletion(void fun()) {
+ return this._runGuarded(fun);
+ }
+
String toString() => "WithErrors ${super.toString()}";
}
@@ -434,31 +445,14 @@ class _PeriodicZoneTimer implements Timer {
}
}
-Stream catchErrors(void body()) {
- _CatchErrorsZone catchErrorsZone;
- StreamController controller;
-
- void onListen() {
- catchErrorsZone.runWaitForCompletion(body);
+runZonedExperimental(body(), { bool onError(error), void onDone() }) {
Lasse Reichstein Nielsen 2013/06/13 12:10:08 I assume the name is experimental too :)
floitsch 2013/06/13 14:38:55 I would keep the name. Until we feel comfortable t
+ // TODO(floitsch): we probably still want to install a new Zone.
+ if (onError == null && onDone == null) return body();
+ if (onError == null) {
+ _Zone zone = new _WaitForCompletionZone(_Zone._current, onDone);
+ return zone.runWaitForCompletion(body);
}
-
- bool handleError(e) {
- controller.add(e);
- return true;
- }
-
- void onDone() {
- controller.close();
- }
-
- catchErrorsZone = new _CatchErrorsZone(_Zone._current, handleError, onDone);
- controller = new StreamController(onListen: onListen);
- return controller.stream;
-}
-
-Future waitForCompletion(void body()) {
- Completer completer = new Completer.sync();
- _Zone zone = new _WaitForCompletionZone(_Zone._current, completer.complete);
- zone.runWaitForCompletion(body);
- return completer.future;
+ if (onDone == null) onDone = () {};
+ _Zone zone = new _CatchErrorsZone(_Zone._current, onError, onDone);
+ return zone.runWaitForCompletion(body);
}
« no previous file with comments | « no previous file | tests/lib/async/catch_errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698