Line data Source code
1 : // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 : // for details. All rights reserved. Use of this source code is governed by a 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import '../delegate/future.dart'; 6 : import 'result.dart'; 7 : 8 : /// A [Future] wrapper that provides synchronous access to the result of the 9 : /// wrapped [Future] once it's completed. 10 : class ResultFuture<T> extends DelegatingFuture<T> { 11 : /// Whether the future has fired and [result] is available. 12 0 : bool get isComplete => result != null; 13 : 14 : /// The result of the wrapped [Future], if it's completed. 15 : /// 16 : /// If it hasn't completed yet, this will be `null`. 17 0 : Result<T>? get result => _result; 18 : Result<T>? _result; 19 : 20 0 : ResultFuture(Future<T> future) : super(future) { 21 0 : Result.capture(future).then((result) { 22 0 : _result = result; 23 : }); 24 : } 25 : }