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

Unified Diff: lib/src/result/error.dart

Issue 1777453002: Modernize the package's style. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Created 4 years, 9 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
Index: lib/src/result/error.dart
diff --git a/lib/src/result/error.dart b/lib/src/result/error.dart
new file mode 100644
index 0000000000000000000000000000000000000000..eecf68e450c873cfee8aac7a019dde4bc6c7f871
--- /dev/null
+++ b/lib/src/result/error.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2016, 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 'dart:async';
+
+import '../result.dart';
+import 'value.dart';
+
+/// A result representing a thrown error.
+class ErrorResult implements Result {
+ final error;
+ final StackTrace stackTrace;
+
+ bool get isValue => false;
+ bool get isError => true;
+ ValueResult get asValue => null;
+ ErrorResult get asError => this;
+
+ ErrorResult(this.error, this.stackTrace);
+
+ void complete(Completer completer) {
+ completer.completeError(error, stackTrace);
+ }
+
+ void addTo(EventSink sink) {
+ sink.addError(error, stackTrace);
+ }
+
+ Future get asFuture => new Future.error(error, stackTrace);
+
+ /// Calls an error handler with the error and stacktrace.
+ ///
+ /// An async error handler function is either a function expecting two
+ /// arguments, which will be called with the error and the stack trace, or it
+ /// has to be a function expecting only one argument, which will be called
+ /// with only the error.
+ void handle(Function errorHandler) {
+ if (errorHandler is ZoneBinaryCallback) {
+ errorHandler(error, stackTrace);
+ } else {
+ errorHandler(error);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698