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); |
+ } |
+} |