提交 e12be13c 编写于 作者: J Jason Malinowski

Merge pull request #918 from jasonmalinowski/delete-asyncenumerable

Delete unused AsyncEnumerable helpers in Workspaces
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Roslyn.Utilities
{
internal static partial class AsyncEnumerable
{
public static IAsyncEnumerable<T> Empty<T>()
{
return EmptyAsyncEnumerable<T>.Instance;
}
public static async Task<IEnumerable<T>> ToTask<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken)
{
using (var enumerator = source.GetEnumerator())
{
var result = new List<T>();
while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
{
result.Add(enumerator.Current);
}
return result;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Roslyn.Utilities
{
internal static partial class AsyncEnumerable
{
public static IAsyncEnumerable<T> Concat<T>(
this IAsyncEnumerable<T> first,
IAsyncEnumerable<T> second)
{
return new ConcatAsyncEnumerable<T>(first, second);
}
private class ConcatAsyncEnumerable<T> : IAsyncEnumerable<T>
{
private readonly IAsyncEnumerable<T> _first;
private readonly IAsyncEnumerable<T> _second;
public ConcatAsyncEnumerable(IAsyncEnumerable<T> first, IAsyncEnumerable<T> second)
{
_first = first;
_second = second;
}
public IAsyncEnumerator<T> GetEnumerator()
{
return new ConcatAsyncEnumerator<T>(_first.GetEnumerator(), _second.GetEnumerator());
}
}
private class ConcatAsyncEnumerator<T> : IAsyncEnumerator<T>
{
private readonly IAsyncEnumerator<T> _first;
private readonly IAsyncEnumerator<T> _second;
private IAsyncEnumerator<T> _currentEnumerator;
public ConcatAsyncEnumerator(IAsyncEnumerator<T> first, IAsyncEnumerator<T> second)
{
_first = first;
_second = second;
_currentEnumerator = first;
}
public T Current { get; private set; }
public async Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
while (true)
{
var currentEnumeratorMoveNext = await _currentEnumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false);
// The current enumerator moved forward successfully. Get it's current
// value and store it, and return true to let the caller know we moved.
if (currentEnumeratorMoveNext)
{
this.Current = _currentEnumerator.Current;
return true;
}
// Current enumerator didn't move forward. If it's the second enumerator
// then we're done.
if (_currentEnumerator == _second)
{
this.Current = default(T);
return false;
}
// The first enumerator finished. Set our current enumerator to the
// second enumerator and then recurse.
_currentEnumerator = _second;
}
}
public void Dispose()
{
_first.Dispose();
_second.Dispose();
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Roslyn.Utilities
{
internal static partial class AsyncEnumerable
{
private class EmptyAsyncEnumerable<T> : IAsyncEnumerable<T>
{
public static readonly IAsyncEnumerable<T> Instance = new EmptyAsyncEnumerable<T>();
private EmptyAsyncEnumerable()
{
}
public IAsyncEnumerator<T> GetEnumerator()
{
return EmptyAsyncEnumerator<T>.Instance;
}
}
private class EmptyAsyncEnumerator<T> : IAsyncEnumerator<T>
{
public static readonly IAsyncEnumerator<T> Instance = new EmptyAsyncEnumerator<T>();
private EmptyAsyncEnumerator()
{
}
public T Current
{
get
{
throw new InvalidOperationException();
}
}
public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
return SpecializedTasks.False;
}
public void Dispose()
{
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Roslyn.Utilities
{
internal static partial class AsyncEnumerable
{
public static IAsyncEnumerable<TResult> Select<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TResult> selector)
{
return new SelectAsyncEnumerable<TSource, TResult>(source, selector);
}
private class SelectAsyncEnumerable<TSource, TResult> : IAsyncEnumerable<TResult>
{
private readonly IAsyncEnumerable<TSource> _source;
private readonly Func<TSource, TResult> _selector;
public SelectAsyncEnumerable(
IAsyncEnumerable<TSource> source,
Func<TSource, TResult> selector)
{
_source = source;
_selector = selector;
}
public IAsyncEnumerator<TResult> GetEnumerator()
{
return new SelectAsyncEnumerator<TSource, TResult>(_source.GetEnumerator(), _selector);
}
}
private class SelectAsyncEnumerator<TSource, TResult> : IAsyncEnumerator<TResult>
{
private readonly IAsyncEnumerator<TSource> _source;
private readonly Func<TSource, TResult> _func;
private TResult _current;
public SelectAsyncEnumerator(IAsyncEnumerator<TSource> source, Func<TSource, TResult> func)
{
_source = source;
_func = func;
}
public TResult Current
{
get
{
return _current;
}
}
public async Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
var result = await _source.MoveNextAsync(cancellationToken).ConfigureAwait(false);
_current = result ? _func(_source.Current) : default(TResult);
return result;
}
public void Dispose()
{
_source.Dispose();
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Roslyn.Utilities
{
internal interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<T> GetEnumerator();
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Roslyn.Utilities
{
internal interface IAsyncEnumerator<out T> : IDisposable
{
T Current { get; }
Task<bool> MoveNextAsync(CancellationToken cancellationToken);
}
}
......@@ -759,12 +759,6 @@
<Compile Include="SymbolId\SymbolKeyResolutionExtensions.cs" />
<Compile Include="Utilities\AbstractSpeculationAnalyzer.cs" />
<Compile Include="Utilities\AnnotationTable.cs" />
<Compile Include="Utilities\Async\AsyncEnumerable.cs" />
<Compile Include="Utilities\Async\AsyncEnumerable_Concat.cs" />
<Compile Include="Utilities\Async\AsyncEnumerable_Empty.cs" />
<Compile Include="Utilities\Async\AsyncEnumerable_Select.cs" />
<Compile Include="Utilities\Async\IAsyncEnumerable.cs" />
<Compile Include="Utilities\Async\IAsyncEnumerator.cs" />
<Compile Include="Utilities\AsyncLazy`1.cs" />
<Compile Include="Utilities\AsyncSemaphore.cs" />
<Compile Include="Utilities\BidirectionalMap.cs" />
......@@ -927,4 +921,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册