Skip to content

Commit a1ea2b5

Browse files
bwilkersonCommit Queue
authored andcommitted
Ensure that the scheduler flushes the event queue
There was only one place that wasn't using a future with a zero length duration, but that's now been fixed. I haven't been able to observe any performance improvement from this change, but it does have the benefit that the code is now consistent. Change-Id: I232728ef2ef9a1000938d0117f611a96c17e9f38 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435662 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent e10267c commit a1ea2b5

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

pkg/analysis_server/integration_test/server/message_scheduler_test.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,28 @@ Entering process messages loop
341341
Complete LspMessage: lsp:initialized
342342
Exit process messages loop
343343
Incoming RequestMessage: lsp:textDocument/hover
344+
Incoming RequestMessage: lsp:textDocument/hover
344345
Entering process messages loop
345346
Start LspMessage: lsp:textDocument/hover
346347
Complete LspMessage: lsp:textDocument/hover
347-
Exit process messages loop
348-
Incoming RequestMessage: lsp:textDocument/hover
349-
Entering process messages loop
350348
Start LspMessage: lsp:textDocument/hover
351349
Complete LspMessage: lsp:textDocument/hover
352350
Exit process messages loop
353351
Pause requested - there are now 1 pauses
354352
Incoming RequestMessage: lsp:textDocument/hover
355353
Incoming RequestMessage: lsp:textDocument/hover
354+
Entering process messages loop
355+
Exit process messages loop
356356
Pause requested - there are now 2 pauses
357357
Incoming RequestMessage: lsp:textDocument/hover
358358
Incoming RequestMessage: lsp:textDocument/hover
359+
Entering process messages loop
360+
Exit process messages loop
359361
Resume requested - there are now 1 pauses
360362
Incoming RequestMessage: lsp:textDocument/hover
361363
Incoming RequestMessage: lsp:textDocument/hover
364+
Entering process messages loop
365+
Exit process messages loop
362366
Resume requested - there are now 0 pauses
363367
Entering process messages loop
364368
Start LspMessage: lsp:textDocument/hover

pkg/analysis_server/lib/src/scheduler/message_scheduler.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class MessageScheduler {
4343
ListQueue<ScheduledMessage>();
4444

4545
/// Whether the [MessageScheduler] is currently processing messages.
46-
bool _isProcessing = false;
46+
bool _processingIsScheduled = false;
4747

4848
/// The number of times [pause] has been called without matching [resume]s.
4949
///
@@ -180,8 +180,9 @@ final class MessageScheduler {
180180
}
181181
}
182182
_pendingMessages.addLast(message);
183-
if (!_isProcessing) {
184-
processMessages();
183+
if (!_processingIsScheduled) {
184+
_processingIsScheduled = true;
185+
Future.delayed(Duration.zero, processMessages);
185186
}
186187
}
187188

@@ -199,14 +200,12 @@ final class MessageScheduler {
199200

200201
/// Dispatch the first message in the queue to be executed.
201202
void processMessages() async {
202-
if (isPaused) {
203-
return;
204-
}
205-
206-
_isProcessing = true;
207203
listener?.startProcessingMessages();
208204
try {
209-
while (_pendingMessages.isNotEmpty && !isPaused) {
205+
while (_pendingMessages.isNotEmpty) {
206+
if (isPaused) {
207+
break;
208+
}
210209
var currentMessage = _pendingMessages.removeFirst();
211210
_activeMessages.addLast(currentMessage);
212211
listener?.addActiveMessage(currentMessage);
@@ -269,7 +268,7 @@ final class MessageScheduler {
269268
server.crashReportingAttachmentsBuilder.forException(error),
270269
);
271270
}
272-
_isProcessing = false;
271+
_processingIsScheduled = false;
273272
listener?.endProcessingMessages();
274273
}
275274

@@ -280,10 +279,11 @@ final class MessageScheduler {
280279
}
281280
_pauseCount--;
282281
listener?.resumeProcessingMessages(_pauseCount);
283-
if (!isPaused && !_isProcessing) {
282+
if (!isPaused && !_processingIsScheduled) {
284283
// Process on the next tick so that the caller to resume() doesn't get
285284
// messages in the queue attributed to their time (or run before they
286285
// complete).
286+
_processingIsScheduled = true;
287287
Future.delayed(Duration.zero, processMessages);
288288
}
289289
}

0 commit comments

Comments
 (0)