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

Unified Diff: watcher/lib/src/file_watcher/polling.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « watcher/lib/src/file_watcher/native.dart ('k') | watcher/lib/src/path_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: watcher/lib/src/file_watcher/polling.dart
diff --git a/watcher/lib/src/file_watcher/polling.dart b/watcher/lib/src/file_watcher/polling.dart
deleted file mode 100644
index 3480ae29eb78094e0b9f86a6d41022cab7039c54..0000000000000000000000000000000000000000
--- a/watcher/lib/src/file_watcher/polling.dart
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library watcher.file_watcher.polling;
-
-import 'dart:async';
-import 'dart:io';
-
-import '../file_watcher.dart';
-import '../resubscribable.dart';
-import '../stat.dart';
-import '../watch_event.dart';
-
-/// Periodically polls a file for changes.
-class PollingFileWatcher extends ResubscribableWatcher implements FileWatcher {
- PollingFileWatcher(String path, {Duration pollingDelay})
- : super(path, () {
- return new _PollingFileWatcher(path,
- pollingDelay != null ? pollingDelay : new Duration(seconds: 1));
- });
-}
-
-class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {
- final String path;
-
- Stream<WatchEvent> get events => _eventsController.stream;
- final _eventsController = new StreamController<WatchEvent>.broadcast();
-
- bool get isReady => _readyCompleter.isCompleted;
-
- Future get ready => _readyCompleter.future;
- final _readyCompleter = new Completer();
-
- /// The timer that controls polling.
- Timer _timer;
-
- /// The previous modification time of the file.
- ///
- /// Used to tell when the file was modified. This is `null` before the file's
- /// mtime has first been checked.
- DateTime _lastModified;
-
- _PollingFileWatcher(this.path, Duration pollingDelay) {
- _timer = new Timer.periodic(pollingDelay, (_) => _poll());
- _poll();
- }
-
- /// Checks the mtime of the file and whether it's been removed.
- Future _poll() async {
- // We don't mark the file as removed if this is the first poll (indicated by
- // [_lastModified] being null). Instead, below we forward the dart:io error
- // that comes from trying to read the mtime below.
- var pathExists = await new File(path).exists();
- if (_eventsController.isClosed) return;
-
- if (_lastModified != null && !pathExists) {
- _eventsController.add(new WatchEvent(ChangeType.REMOVE, path));
- close();
- return;
- }
-
- var modified;
- try {
- try {
- modified = await getModificationTime(path);
- } finally {
- if (_eventsController.isClosed) return;
- }
- } on FileSystemException catch (error, stackTrace) {
- _eventsController.addError(error, stackTrace);
- close();
- return;
- }
-
- if (_lastModified == modified) return;
-
- if (_lastModified == null) {
- // If this is the first poll, don't emit an event, just set the last mtime
- // and complete the completer.
- _lastModified = modified;
- _readyCompleter.complete();
- } else {
- _lastModified = modified;
- _eventsController.add(new WatchEvent(ChangeType.MODIFY, path));
- }
- }
-
- void close() {
- _timer.cancel();
- _eventsController.close();
- }
-}
« no previous file with comments | « watcher/lib/src/file_watcher/native.dart ('k') | watcher/lib/src/path_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698