blob: 1b68f129cbdf2fede6b3047c0203d213d9708816 [file] [log] [blame]
// 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);
}
}