| 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();
|
|
|