Never
parent
ed0990e402
commit
c16433e0fe
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@ namespace UniTask.NetCoreTests.Linq
|
|||
xs.Length.Should().Be(1);
|
||||
xs[0].Should().Be(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue