提交 e6cce92d 编写于 作者: C Cyrus Najmabadi

Use immutable arrays.

上级 4990fe17
......@@ -313,7 +313,7 @@ private void AddFilteredInfos(ImmutableArray<DesignerAttributeData> data, ArrayB
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public Task ReportDesignerAttributeDataAsync(IList<DesignerAttributeData> data, CancellationToken cancellationToken)
public Task ReportDesignerAttributeDataAsync(ImmutableArray<DesignerAttributeData> data, CancellationToken cancellationToken)
{
Contract.ThrowIfNull(_workQueue);
_workQueue.AddWork(data);
......
......@@ -181,7 +181,7 @@ public ImmutableArray<TodoCommentData> GetTodoItems(Workspace workspace, Documen
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public Task ReportTodoCommentDataAsync(DocumentId documentId, List<TodoCommentData> infos, CancellationToken cancellationToken)
public Task ReportTodoCommentDataAsync(DocumentId documentId, ImmutableArray<TodoCommentData> infos, CancellationToken cancellationToken)
{
Contract.ThrowIfNull(_workQueue);
_workQueue.AddWork(new DocumentAndComments(documentId, infos.ToImmutableArray()));
......
......@@ -4,7 +4,7 @@
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
......@@ -19,6 +19,6 @@ namespace Microsoft.CodeAnalysis.DesignerAttribute
internal interface IDesignerAttributeListener
{
Task OnProjectRemovedAsync(ProjectId projectId, CancellationToken cancellationToken);
Task ReportDesignerAttributeDataAsync(IList<DesignerAttributeData> data, CancellationToken cancellationToken);
Task ReportDesignerAttributeDataAsync(ImmutableArray<DesignerAttributeData> data, CancellationToken cancellationToken);
}
}
......@@ -4,7 +4,7 @@
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
......@@ -17,6 +17,6 @@ namespace Microsoft.CodeAnalysis.TodoComments
internal interface ITodoCommentsListener
{
Task OnDocumentRemovedAsync(DocumentId documentId, CancellationToken cancellationToken);
Task ReportTodoCommentDataAsync(DocumentId documentId, List<TodoCommentData> data, CancellationToken cancellationToken);
Task ReportTodoCommentDataAsync(DocumentId documentId, ImmutableArray<TodoCommentData> data, CancellationToken cancellationToken);
}
}
......@@ -90,20 +90,38 @@ public void AddWork(IEnumerable<TItem> items)
{
// add our work to the set we'll process in the next batch.
_nextBatch.AddRange(items);
TryKickOffNextBatchTask();
}
}
public void AddWork(ImmutableArray<TItem> items)
{
// Don't do any more work if we've been asked to shutdown.
if (_cancellationToken.IsCancellationRequested)
return;
lock (_gate)
{
// add our work to the set we'll process in the next batch.
_nextBatch.AddRange(items);
TryKickOffNextBatchTask();
}
}
if (!_taskInFlight)
{
// No in-flight task. Kick one off to process these messages a second from now.
// We always attach the task to the previous one so that notifications to the ui
// follow the same order as the notification the OOP server sent to us.
_updateTask = _updateTask.ContinueWithAfterDelayFromAsync(
_ => ProcessNextBatchAsync(_cancellationToken),
_cancellationToken,
(int)_delay.TotalMilliseconds,
TaskContinuationOptions.RunContinuationsAsynchronously,
TaskScheduler.Default);
_taskInFlight = true;
}
private void TryKickOffNextBatchTask()
{
if (!_taskInFlight)
{
// No in-flight task. Kick one off to process these messages a second from now.
// We always attach the task to the previous one so that notifications to the ui
// follow the same order as the notification the OOP server sent to us.
_updateTask = _updateTask.ContinueWithAfterDelayFromAsync(
_ => ProcessNextBatchAsync(_cancellationToken),
_cancellationToken,
(int)_delay.TotalMilliseconds,
TaskContinuationOptions.RunContinuationsAsynchronously,
TaskScheduler.Default);
_taskInFlight = true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册