master
neuecc 2020-05-08 15:16:43 +09:00
parent ed0990e402
commit c16433e0fe
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,57 @@
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{
public static partial class UniTaskAsyncEnumerable
{
public static IUniTaskAsyncEnumerable<T> Never<T>()
{
return Cysharp.Threading.Tasks.Linq.Never<T>.Instance;
}
}
internal class Never<T> : IUniTaskAsyncEnumerable<T>
{
public static readonly IUniTaskAsyncEnumerable<T> Instance = new Never<T>();
Never()
{
}
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
return new Enumerator(cancellationToken);
}
class Enumerator : IUniTaskAsyncEnumerator<T>
{
CancellationToken cancellationToken;
public Enumerator(CancellationToken cancellationToken)
{
this.cancellationToken = cancellationToken;
}
public T Current => default;
public UniTask<bool> MoveNextAsync()
{
var tcs = new UniTaskCompletionSource<bool>();
cancellationToken.Register(state =>
{
var task = (UniTaskCompletionSource<bool>)state;
task.TrySetCanceled(cancellationToken);
}, tcs);
return tcs.Task;
}
public UniTask DisposeAsync()
{
return default;
}
}
}
}

View File

@ -59,6 +59,7 @@ namespace UniTask.NetCoreTests.Linq
xs.Length.Should().Be(1);
xs[0].Should().Be(value);
}
}