Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Side by Side Diff: pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library descriptor.directory; 5 library descriptor.directory;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:pathos/path.dart' as path; 10 import 'package:pathos/path.dart' as path;
(...skipping 28 matching lines...) Expand all
39 'validating directory:\n${describe()}'); 39 'validating directory:\n${describe()}');
40 40
41 Future validateNow([String parent]) { 41 Future validateNow([String parent]) {
42 if (parent == null) parent = defaultRoot; 42 if (parent == null) parent = defaultRoot;
43 var fullPath = path.join(parent, name); 43 var fullPath = path.join(parent, name);
44 if (!new Directory(fullPath).existsSync()) { 44 if (!new Directory(fullPath).existsSync()) {
45 throw "Directory not found: '$fullPath'."; 45 throw "Directory not found: '$fullPath'.";
46 } 46 }
47 47
48 return Future.wait(contents.map((entry) { 48 return Future.wait(contents.map((entry) {
49 return new Future.of(() => entry.validateNow(fullPath)) 49 return new Future.sync(() => entry.validateNow(fullPath))
50 .then((_) => null) 50 .then((_) => null)
51 .catchError((e) => e); 51 .catchError((e) => e);
52 })).then((results) { 52 })).then((results) {
53 var errors = results.where((e) => e != null); 53 var errors = results.where((e) => e != null);
54 if (errors.isEmpty) return; 54 if (errors.isEmpty) return;
55 throw _DirectoryValidationError.merge(errors); 55 throw _DirectoryValidationError.merge(errors);
56 }); 56 });
57 } 57 }
58 58
59 Stream<List<int>> load(String pathToLoad) { 59 Stream<List<int>> load(String pathToLoad) {
60 return futureStream(new Future.immediate(null).then((_) { 60 return futureStream(new Future.value().then((_) {
61 if (_path.isAbsolute(pathToLoad)) { 61 if (_path.isAbsolute(pathToLoad)) {
62 throw "Can't load absolute path '$pathToLoad'."; 62 throw "Can't load absolute path '$pathToLoad'.";
63 } 63 }
64 64
65 var split = _path.split(_path.normalize(pathToLoad)); 65 var split = _path.split(_path.normalize(pathToLoad));
66 if (split.isEmpty || split.first == '.' || split.first == '..') { 66 if (split.isEmpty || split.first == '.' || split.first == '..') {
67 throw "Can't load '$pathToLoad' from within '$name'."; 67 throw "Can't load '$pathToLoad' from within '$name'.";
68 } 68 }
69 69
70 var matchingEntries = contents.where((entry) => 70 var matchingEntries = contents.where((entry) =>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 _DirectoryValidationError(Iterable errors) 122 _DirectoryValidationError(Iterable errors)
123 : errors = errors.map((e) => e.toString()).toList(); 123 : errors = errors.map((e) => e.toString()).toList();
124 124
125 String toString() { 125 String toString() {
126 if (errors.length == 1) return errors.single; 126 if (errors.length == 1) return errors.single;
127 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) 127 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* '))
128 .join('\n'); 128 .join('\n');
129 } 129 }
130 } 130 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/scheduled_server.dart ('k') | pkg/scheduled_test/lib/src/descriptor/file_descriptor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698