Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Sfshaza / main.dart
Last active September 9, 2015 17:06
futures/sequential-processing
// 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() {
expensiveA()
.then((aValue) => expensiveB())
.then((bValue) => expensiveC())
@Sfshaza
Sfshaza / main.dart
Last active September 9, 2015 17:06
futures/futures-api-catch-error
// 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';
printDailyNewsDigest() {
var future = gatherNewsReports();
future.then((content) => print(content))
.catchError((e) => handleError(e));
@Sfshaza
Sfshaza / main.dart
Last active December 21, 2017 22:11
futures/futures-api
// 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';
printDailyNewsDigest() {
var future = gatherNewsReports();
future.then((content) => print(content));
}
@Sfshaza
Sfshaza / main.dart
Last active September 9, 2015 17:06
futures/async-await-catch-error
// 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 {
try {
String news = await gatherNewsReports();
@Sfshaza
Sfshaza / main.dart
Last active December 21, 2017 21:20
futures/async-await
// 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);
@Sfshaza
Sfshaza / main.dart
Created August 24, 2015 17:19
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:html';
import 'dart:async';
Future printDailyNewsDigest() async {
String news = await gatherNewsReports();
print(news);
@Sfshaza
Sfshaza / main.dart
Last active August 29, 2015 14:27
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));
@Sfshaza
Sfshaza / main.dart
Last active August 29, 2015 14:27
futures/sequential-processing
// 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() {
expensiveA()
.then((aValue) => expensiveB())
.then((bValue) => expensiveC())
@Sfshaza
Sfshaza / main.dart
Last active August 29, 2015 14:27
futures/futures-api-catch-error
// 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';
void printDailyNewsDigest() {
String path =
'https://www.dartlang.org/samples-files/dailyNewsDigest.txt';
@Sfshaza
Sfshaza / main.dart
Last active August 29, 2015 14:27
futures/futures-api
// 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';
void printDailyNewsDigest() {
String path =
'https://www.dartlang.org/samples-files/dailyNewsDigest.txt';