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

Side by Side Diff: observatory_pub_packages/watcher/src/directory_watcher.dart

Issue 816693004: Add observatory_pub_packages snapshot to third_party (Closed) Base URL: http://dart.googlecode.com/svn/third_party/
Patch Set: Created 6 years 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
(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.directory_watcher;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'watch_event.dart';
11 import 'directory_watcher/linux.dart';
12 import 'directory_watcher/mac_os.dart';
13 import 'directory_watcher/windows.dart';
14 import 'directory_watcher/polling.dart';
15
16 /// Watches the contents of a directory and emits [WatchEvent]s when something
17 /// in the directory has changed.
18 abstract class DirectoryWatcher {
19 /// The directory whose contents are being monitored.
20 String get directory;
21
22 /// The broadcast [Stream] of events that have occurred to files in
23 /// [directory].
24 ///
25 /// Changes will only be monitored while this stream has subscribers. Any
26 /// file changes that occur during periods when there are no subscribers
27 /// will not be reported the next time a subscriber is added.
28 Stream<WatchEvent> get events;
29
30 /// Whether the watcher is initialized and watching for file changes.
31 ///
32 /// This is true if and only if [ready] is complete.
33 bool get isReady;
34
35 /// A [Future] that completes when the watcher is initialized and watching
36 /// for file changes.
37 ///
38 /// If the watcher is not currently monitoring the directory (because there
39 /// are no subscribers to [events]), this returns a future that isn't
40 /// complete yet. It will complete when a subscriber starts listening and
41 /// the watcher finishes any initialization work it needs to do.
42 ///
43 /// If the watcher is already monitoring, this returns an already complete
44 /// future.
45 Future get ready;
46
47 /// Creates a new [DirectoryWatcher] monitoring [directory].
48 ///
49 /// If a native directory watcher is available for this platform, this will
50 /// use it. Otherwise, it will fall back to a [PollingDirectoryWatcher].
51 ///
52 /// If [_pollingDelay] is passed, it specifies the amount of time the watcher
53 /// will pause between successive polls of the directory contents. Making this
54 /// shorter will give more immediate feedback at the expense of doing more IO
55 /// and higher CPU usage. Defaults to one second. Ignored for non-polling
56 /// watchers.
57 factory DirectoryWatcher(String directory, {Duration pollingDelay}) {
58 if (FileSystemEntity.isWatchSupported) {
59 if (Platform.isLinux) return new LinuxDirectoryWatcher(directory);
60 if (Platform.isMacOS) return new MacOSDirectoryWatcher(directory);
61 if (Platform.isWindows) return new WindowsDirectoryWatcher(directory);
62 }
63 return new PollingDirectoryWatcher(directory, pollingDelay: pollingDelay);
64 }
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698