OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import "dart:convert"; | 7 import "dart:convert"; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
10 | 10 |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar | 623 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar |
624 /// objects, and [Future]s) and recursively resolves all the [Future]s contained | 624 /// objects, and [Future]s) and recursively resolves all the [Future]s contained |
625 /// within. | 625 /// within. |
626 /// | 626 /// |
627 /// Completes with the fully resolved structure. | 627 /// Completes with the fully resolved structure. |
628 Future/*<T>*/ awaitObject/*<T>*/(/*=T*/ object) async { | 628 Future/*<T>*/ awaitObject/*<T>*/(/*=T*/ object) async { |
629 // Unroll nested futures. | 629 // Unroll nested futures. |
630 if (object is Future) return await awaitObject(await object); | 630 if (object is Future) return await awaitObject(await object); |
631 | 631 |
632 if (object is Iterable) { | 632 if (object is Iterable) { |
633 // TODO(nweiz): Remove the unnecessary as check when sdk#26965 is fixed. | 633 return await Future.wait(object.map(awaitObject)) as List/*=T*/; |
634 return await Future.wait((object as Iterable).map(awaitObject)) | |
635 as List/*=T*/; | |
636 } | 634 } |
637 | 635 |
638 if (object is Map) { | 636 if (object is Map) { |
639 // TODO(nweiz): Remove the unnecessary as check when sdk#26965 is fixed. | |
640 var oldMap = object as Map; | |
641 var newMap = {}; | 637 var newMap = {}; |
642 await Future.wait(oldMap.keys.map((key) async { | 638 await Future.wait(object.keys.map((key) async { |
643 newMap[key] = await awaitObject(await oldMap[key]); | 639 newMap[key] = await awaitObject(await object[key]); |
644 })); | 640 })); |
645 return newMap as Map/*=T*/; | 641 return newMap as Map/*=T*/; |
646 } | 642 } |
647 | 643 |
648 return object; | 644 return object; |
649 } | 645 } |
650 | 646 |
651 /// Whether "special" strings such as Unicode characters or color escapes are | 647 /// Whether "special" strings such as Unicode characters or color escapes are |
652 /// safe to use. | 648 /// safe to use. |
653 /// | 649 /// |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 } else { | 779 } else { |
784 throw new ApplicationException(message); | 780 throw new ApplicationException(message); |
785 } | 781 } |
786 } | 782 } |
787 | 783 |
788 /// Throw a [DataException] with [message] to indicate that the command has | 784 /// Throw a [DataException] with [message] to indicate that the command has |
789 /// failed because of invalid input data. | 785 /// failed because of invalid input data. |
790 /// | 786 /// |
791 /// This will report the error and cause pub to exit with [exit_codes.DATA]. | 787 /// This will report the error and cause pub to exit with [exit_codes.DATA]. |
792 void dataError(String message) => throw new DataException(message); | 788 void dataError(String message) => throw new DataException(message); |
OLD | NEW |