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

Side by Side Diff: pkg/watcher/lib/src/utils.dart

Issue 441483004: pkg/watcher: prepare for 0.9.3 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 4 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 watcher.utils; 5 library watcher.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:collection'; 9 import 'dart:collection';
10 10
11 /// Returns `true` if [error] is a [FileSystemException] for a missing 11 /// Returns `true` if [error] is a [FileSystemException] for a missing
12 /// directory. 12 /// directory.
13 bool isDirectoryNotFoundException(error) { 13 bool isDirectoryNotFoundException(error) {
14 if (error is! FileSystemException) return false; 14 if (error is! FileSystemException) return false;
15 15
16 // See dartbug.com/12461 and tests/standalone/io/directory_error_test.dart. 16 // See dartbug.com/12461 and tests/standalone/io/directory_error_test.dart.
17 var notFoundCode = Platform.operatingSystem == "windows" ? 3 : 2; 17 var notFoundCode = Platform.operatingSystem == "windows" ? 3 : 2;
18 return error.osError.errorCode == notFoundCode; 18 return error.osError.errorCode == notFoundCode;
19 } 19 }
20 20
21 /// Returns the union of all elements in each set in [sets]. 21 /// Returns the union of all elements in each set in [sets].
22 Set unionAll(Iterable<Set> sets) => 22 Set unionAll(Iterable<Set> sets) =>
23 sets.fold(new Set(), (union, set) => union.union(set)); 23 sets.fold(new Set(), (union, set) => union.union(set));
24 24
25 /// Returns a buffered stream that will emit the same values as the stream 25 /// Returns a buffered stream that will emit the same values as the stream
26 /// returned by [future] once [future] completes. 26 /// returned by [future] once [future] completes.
27 /// 27 ///
28 /// If [future] completes to an error, the return value will emit that error and 28 /// If [future] completes to an error, the return value will emit that error and
29 /// then close. 29 /// then close.
30 /// 30 ///
31 /// If [broadcast] is true, a broadcast stream is returned. This assumes that 31 /// If [broadcast] is true, a broadcast stream is returned. This assumes that
32 /// the stream returned by [future] will be a broadcast stream as well. 32 /// the stream returned by [future] will be a broadcast stream as well.
33 /// [broadcast] defaults to false. 33 /// [broadcast] defaults to false.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return controller.stream; 69 return controller.stream;
70 } 70 }
71 71
72 /// Like [new Future], but avoids around issue 11911 by using [new Future.value] 72 /// Like [new Future], but avoids around issue 11911 by using [new Future.value]
73 /// under the covers. 73 /// under the covers.
74 Future newFuture(callback()) => new Future.value().then((_) => callback()); 74 Future newFuture(callback()) => new Future.value().then((_) => callback());
75 75
76 /// Returns a [Future] that completes after pumping the event queue [times] 76 /// Returns a [Future] that completes after pumping the event queue [times]
77 /// times. By default, this should pump the event queue enough times to allow 77 /// times. By default, this should pump the event queue enough times to allow
78 /// any code to run, as long as it's not waiting on some external event. 78 /// any code to run, as long as it's not waiting on some external event.
79 Future pumpEventQueue([int times=20]) { 79 Future pumpEventQueue([int times = 20]) {
80 if (times == 0) return new Future.value(); 80 if (times == 0) return new Future.value();
81 // We use a delayed future to allow microtask events to finish. The 81 // We use a delayed future to allow microtask events to finish. The
82 // Future.value or Future() constructors use scheduleMicrotask themselves and 82 // Future.value or Future() constructors use scheduleMicrotask themselves and
83 // would therefore not wait for microtask callbacks that are scheduled after 83 // would therefore not wait for microtask callbacks that are scheduled after
84 // invoking this method. 84 // invoking this method.
85 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); 85 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1));
86 } 86 }
87 87
88 /// A stream transformer that batches all events that are sent at the same time. 88 /// A stream transformer that batches all events that are sent at the same time.
89 /// 89 ///
(...skipping 18 matching lines...) Expand all
108 }); 108 });
109 }, handleDone: (sink) { 109 }, handleDone: (sink) {
110 if (batch.isNotEmpty) { 110 if (batch.isNotEmpty) {
111 sink.add(batch.toList()); 111 sink.add(batch.toList());
112 batch.clear(); 112 batch.clear();
113 } 113 }
114 sink.close(); 114 sink.close();
115 }).bind(input); 115 }).bind(input);
116 } 116 }
117 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698