Last active
December 21, 2017 21:20
-
-
Save Sfshaza/c0e8f5c38489ddeccb5a to your computer and use it in GitHub Desktop.
futures/async-await
This file contains 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:html'; | |
import 'dart:async'; | |
Future printDailyNewsDigest() async { | |
String news = await gatherNewsReports(); | |
print(news); | |
} | |
main() { | |
printDailyNewsDigest(); | |
printWinningLotteryNumbers(); | |
printWeatherForecast(); | |
printBaseballScore(); | |
} | |
printWinningLotteryNumbers() { | |
print('Winning lotto numbers: [23, 63, 87, 26, 2]'); | |
} | |
printWeatherForecast() { | |
print('Tomorrow\'s forecast: 70F, sunny.'); | |
} | |
printBaseballScore() { | |
print('Baseball score: Red Sox 10, Yankees 0'); | |
} | |
// Imagine that this function is more complex and slow. :) | |
Future gatherNewsReports() async { | |
String path = | |
'https://www.dartlang.org/f/dailyNewsDigest.txt'; | |
return (await HttpRequest.getString(path)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment