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

Unified Diff: lib/src/async_handler.dart

Issue 2171743003: Add the package implementation. (Closed) Base URL: git@github.com:dart-lang/shelf_packages_handler.git@master
Patch Set: Code review changes Created 4 years, 5 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 | « lib/shelf_packages_handler.dart ('k') | lib/src/dir_handler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/async_handler.dart
diff --git a/lib/src/async_handler.dart b/lib/src/async_handler.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1b68f129cbdf2fede6b3047c0203d213d9708816
--- /dev/null
+++ b/lib/src/async_handler.dart
@@ -0,0 +1,24 @@
+// 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 'package:async/async.dart';
+import 'package:shelf/shelf.dart';
+
+class AsyncHandler {
+ final ResultFuture<Handler> _future;
+
+ AsyncHandler(Future<Handler> future) : _future = new ResultFuture(future);
+
+ call(Request request) {
+ if (_future.result == null) {
+ return _future.then((handler) => handler(request));
+ }
+
+ if (_future.result.isError) return _future;
+
+ return _future.result.asValue.value(request);
+ }
+}
« no previous file with comments | « lib/shelf_packages_handler.dart ('k') | lib/src/dir_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698