| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library watcher; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'src/watch_event.dart'; | |
| 11 import 'src/directory_watcher.dart'; | |
| 12 import 'src/file_watcher.dart'; | |
| 13 | |
| 14 export 'src/watch_event.dart'; | |
| 15 export 'src/directory_watcher.dart'; | |
| 16 export 'src/directory_watcher/polling.dart'; | |
| 17 export 'src/file_watcher.dart'; | |
| 18 export 'src/file_watcher/polling.dart'; | |
| 19 | |
| 20 abstract class Watcher { | |
| 21 /// The path to the file or directory whose contents are being monitored. | |
| 22 String get path; | |
| 23 | |
| 24 /// The broadcast [Stream] of events that have occurred to the watched file or | |
| 25 /// files in the watched directory. | |
| 26 /// | |
| 27 /// Changes will only be monitored while this stream has subscribers. Any | |
| 28 /// changes that occur during periods when there are no subscribers will not | |
| 29 /// be reported the next time a subscriber is added. | |
| 30 Stream<WatchEvent> get events; | |
| 31 | |
| 32 /// Whether the watcher is initialized and watching for changes. | |
| 33 /// | |
| 34 /// This is true if and only if [ready] is complete. | |
| 35 bool get isReady; | |
| 36 | |
| 37 /// A [Future] that completes when the watcher is initialized and watching for | |
| 38 /// changes. | |
| 39 /// | |
| 40 /// If the watcher is not currently monitoring the file or directory (because | |
| 41 /// there are no subscribers to [events]), this returns a future that isn't | |
| 42 /// complete yet. It will complete when a subscriber starts listening and the | |
| 43 /// watcher finishes any initialization work it needs to do. | |
| 44 /// | |
| 45 /// If the watcher is already monitoring, this returns an already complete | |
| 46 /// future. | |
| 47 Future get ready; | |
| 48 | |
| 49 /// Creates a new [DirectoryWatcher] or [FileWatcher] monitoring [path], | |
| 50 /// depending on whether it's a file or directory. | |
| 51 /// | |
| 52 /// If a native watcher is available for this platform, this will use it. | |
| 53 /// Otherwise, it will fall back to a polling watcher. Notably, watching | |
| 54 /// individual files is not natively supported on Windows, although watching | |
| 55 /// directories is. | |
| 56 /// | |
| 57 /// If [pollingDelay] is passed, it specifies the amount of time the watcher | |
| 58 /// will pause between successive polls of the contents of [path]. Making this | |
| 59 /// shorter will give more immediate feedback at the expense of doing more IO | |
| 60 /// and higher CPU usage. Defaults to one second. Ignored for non-polling | |
| 61 /// watchers. | |
| 62 factory Watcher(String path, {Duration pollingDelay}) { | |
| 63 if (new File(path).existsSync()) { | |
| 64 return new FileWatcher(path, pollingDelay: pollingDelay); | |
| 65 } else { | |
| 66 return new DirectoryWatcher(path, pollingDelay: pollingDelay); | |
| 67 } | |
| 68 } | |
| 69 } | |
| OLD | NEW |