Last active
September 9, 2015 17:06
-
-
Save Sfshaza/7babd77d2b5460bc9251 to your computer and use it in GitHub Desktop.
futures/waiting-on-futures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2013, 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'; | |
void main() { | |
Future.wait([expensiveA(), expensiveB(), expensiveC()]) | |
.then((List responses) => chooseBestResponse(responses)) | |
.catchError((e) => handleError(e)); | |
} | |
Future expensiveA() => new Future.value('from expensiveA'); | |
Future expensiveB() => new Future.value('from expensiveB'); | |
Future expensiveC() => new Future.value('from expensiveC'); | |
doSomethingWith(value) { | |
print(value); | |
} | |
chooseBestResponse(List responses) { | |
print(responses[1]); | |
} | |
handleError(e) { | |
print('error handled'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment