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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2993303002: Don't schedule timer if knownFilesSetChanges stream is not requested. (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 0e12d6fd812f85b68e3d0c82c797f4f8726bae88..2ec9f50f48f28df3996de5ecda5728b52d7c0331 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -31,10 +31,10 @@ import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:front_end/src/base/api_signature.dart';
import 'package:front_end/src/base/performace_logger.dart';
+import 'package:front_end/src/byte_store/byte_store.dart';
import 'package:front_end/src/fasta/builder/builder.dart' as fasta;
import 'package:front_end/src/fasta/parser/parser.dart' as fasta;
import 'package:front_end/src/fasta/scanner.dart' as fasta;
-import 'package:front_end/src/byte_store/byte_store.dart';
import 'package:meta/meta.dart';
/**
@@ -704,6 +704,11 @@ class FileSystemState {
*/
Timer _knownFilesSetChangesTimer;
+ /**
+ * Whether the [knownFilesSetChanges] stream is requested.
+ */
+ bool _knownFilesSetChangesRequested = false;
+
/**
* The controller for the [knownFilesSetChanges] stream.
*/
@@ -759,8 +764,15 @@ class FileSystemState {
* Return the [Stream] that is periodically notified about changes to the
* known files set.
*/
- Stream<KnownFilesSetChange> get knownFilesSetChanges =>
- _knownFilesSetChangesController.stream;
+ Stream<KnownFilesSetChange> get knownFilesSetChanges {
+ // If this is the first (and actually the only) time when the stream is
+ // requested, schedule the timer to send updates.
+ if (!_knownFilesSetChangesRequested) {
+ _knownFilesSetChangesRequested = true;
+ _scheduleKnownFilesSetChange();
+ }
+ return _knownFilesSetChangesController.stream;
+ }
@visibleForTesting
FileSystemStateTestView get test => _testView;
@@ -906,6 +918,11 @@ class FileSystemState {
}
void _scheduleKnownFilesSetChange() {
+ // Schedule the timer only if there is a client who listens the stream.
+ if (!_knownFilesSetChangesRequested) {
+ return;
+ }
+
Duration delay = _knownFilesSetChangesDelay ?? new Duration(seconds: 1);
_knownFilesSetChangesTimer ??= new Timer(delay, () {
Set<String> addedFiles = _addedKnownFiles.toSet();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698