Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Last active September 9, 2015 17:06
Show Gist options
  • Save Sfshaza/7babd77d2b5460bc9251 to your computer and use it in GitHub Desktop.
Save Sfshaza/7babd77d2b5460bc9251 to your computer and use it in GitHub Desktop.
futures/waiting-on-futures
// 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