| OLD | NEW |
| 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]. |
| 22 Set unionAll(Iterable<Set> sets) => |
| 23 sets.fold(new Set(), (union, set) => union.union(set)); |
| 24 |
| 21 /// 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 |
| 22 /// returned by [future] once [future] completes. | 26 /// returned by [future] once [future] completes. |
| 23 /// | 27 /// |
| 24 /// 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 |
| 25 /// then close. | 29 /// then close. |
| 26 Stream futureStream(Future<Stream> future) { | 30 Stream futureStream(Future<Stream> future) { |
| 27 var controller = new StreamController(sync: true); | 31 var controller = new StreamController(sync: true); |
| 28 future.then((stream) { | 32 future.then((stream) { |
| 29 stream.listen( | 33 stream.listen( |
| 30 controller.add, | 34 controller.add, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 }); | 68 }); |
| 65 }, handleDone: (sink) { | 69 }, handleDone: (sink) { |
| 66 if (batch.isNotEmpty) { | 70 if (batch.isNotEmpty) { |
| 67 sink.add(batch.toList()); | 71 sink.add(batch.toList()); |
| 68 batch.clear(); | 72 batch.clear(); |
| 69 } | 73 } |
| 70 sink.close(); | 74 sink.close(); |
| 71 }).bind(input); | 75 }).bind(input); |
| 72 } | 76 } |
| 73 } | 77 } |
| OLD | NEW |