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

Unified Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 587783003: Replace AnalysisServerListener with Stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merges and fixes for comments Created 6 years, 3 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 | pkg/analysis_server/lib/src/domain_execution.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/analysis_server.dart
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 447af90be2a6a997ba97cda0a4f08c478ed822bf..abc47c867543f8772b2c670f4b617dbcd7da2240 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -208,9 +208,14 @@ class AnalysisServer {
new HashMap<AnalysisContext, Completer<AnalysisDoneReason>>();
/**
- * The listeners that are listening for lifecycle events from this server.
+ * The controller that is notified when analysis is started.
*/
- List<AnalysisServerListener> listeners = <AnalysisServerListener>[];
+ StreamController<AnalysisContext> _onAnalysisStartedController;
+
+ /**
+ * The controller that is notified when analysis is complete.
+ */
+ StreamController _onAnalysisCompleteController;
/**
* True if any exceptions thrown by analysis should be propagated up the call
@@ -235,6 +240,8 @@ class AnalysisServer {
contextDirectoryManager =
new ServerContextManager(this, resourceProvider, packageMapProvider);
AnalysisEngine.instance.logger = new AnalysisLogger();
+ _onAnalysisStartedController = new StreamController.broadcast();
+ _onAnalysisCompleteController = new StreamController.broadcast();
running = true;
Notification notification = new ServerConnectedParams().toNotification();
channel.sendNotification(notification);
@@ -256,7 +263,7 @@ class AnalysisServer {
* Schedules analysis of the given context.
*/
void schedulePerformAnalysisOperation(AnalysisContext context) {
- _notifyAnalysisStarted(context);
+ _onAnalysisStartedController.add(context);
scheduleOperation(new PerformAnalysisOperation(context, false));
}
@@ -335,16 +342,18 @@ class AnalysisServer {
}
/**
- * Add the given [listener] to the list of listeners that are listening for
- * lifecycle events from this server.
+ * The stream that is notified when analysis of a context is started.
*/
- void addAnalysisServerListener(AnalysisServerListener listener) {
- if (!listeners.contains(listener)) {
- listeners.add(listener);
- }
+ Stream<AnalysisContext> get onAnalysisStarted {
+ return _onAnalysisStartedController.stream;
}
/**
+ * The stream that is notified when analysis is complete.
+ */
+ Stream get onAnalysisComplete => _onAnalysisCompleteController.stream;
+
+ /**
* Adds the given [ServerOperation] to the queue, but does not schedule
* operations execution.
*/
@@ -483,7 +492,7 @@ class AnalysisServer {
_schedulePerformOperation();
} else {
sendStatusNotification(null);
- _notifyAnalysisComplete();
+ _onAnalysisCompleteController.add(null);
}
}
}
@@ -500,14 +509,6 @@ class AnalysisServer {
}
/**
- * Remove the given [listener] from the list of listeners that are listening
- * for lifecycle events from this server.
- */
- void removeAnalysisServerListener(AnalysisServerListener listener) {
- listeners.remove(listener);
- }
-
- /**
* Send status notification to the client. The `operation` is the operation
* being performed or `null` if analysis is complete.
*/
@@ -904,24 +905,6 @@ class AnalysisServer {
}
/**
- * Notify all listeners that analysis of [context] is started.
- */
- void _notifyAnalysisStarted(AnalysisContext context) {
- listeners.forEach((AnalysisServerListener listener) {
- listener.analysisStarted(context);
- });
- }
-
- /**
- * Notify all listeners that analysis is complete.
- */
- void _notifyAnalysisComplete() {
- listeners.forEach((AnalysisServerListener listener) {
- listener.analysisComplete();
- });
- }
-
- /**
* Schedules [performOperation] exection.
*/
void _schedulePerformOperation() {
@@ -955,19 +938,4 @@ class AnalysisServer {
}
}
-/**
- * An object that is listening for lifecycle events from an analysis server.
- */
-abstract class AnalysisServerListener {
- /**
- * Analysis is complete.
- */
- void analysisComplete();
-
- /**
- * Analysis is started.
- */
- void analysisStarted(AnalysisContext context);
-}
-
typedef void OptionUpdater(AnalysisOptionsImpl options);
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_execution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698