You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/UniTask/Runtime/Linq/Never.cs

56 lines
1.4 KiB
C#

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)
{
return new _Never(cancellationToken);
}
class _Never : IUniTaskAsyncEnumerator<T>
{
CancellationToken cancellationToken;
public _Never(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;
}
}
}
}