com.alicizax.unity.cysharp..../Runtime/Linq/Throw.cs
陈思海 0f01d0a681
Some checks are pending
Sync Github To Image / sync-gitlink (push) Waiting to run
Sync Github To Image / sync-gitlab (push) Waiting to run
Sync Github To Image / sync-gitee (push) Waiting to run
Sync Github To Image / sync-atomgit (push) Waiting to run
Sync Github To Image / sync-gitcode (push) Waiting to run
Sync Github To Image / sync-framagit (push) Waiting to run
init
2025-01-09 11:14:16 +08:00

54 lines
1.5 KiB
C#

using Cysharp.Threading.Tasks.Internal;
using System;
using System.Threading;
namespace Cysharp.Threading.Tasks.Linq
{
public static partial class UniTaskAsyncEnumerable
{
public static IUniTaskAsyncEnumerable<TValue> Throw<TValue>(Exception exception)
{
return new Throw<TValue>(exception);
}
}
internal class Throw<TValue> : IUniTaskAsyncEnumerable<TValue>
{
readonly Exception exception;
public Throw(Exception exception)
{
this.exception = exception;
}
public IUniTaskAsyncEnumerator<TValue> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return new _Throw(exception, cancellationToken);
}
class _Throw : IUniTaskAsyncEnumerator<TValue>
{
readonly Exception exception;
CancellationToken cancellationToken;
public _Throw(Exception exception, CancellationToken cancellationToken)
{
this.exception = exception;
this.cancellationToken = cancellationToken;
}
public TValue Current => default;
public UniTask<bool> MoveNextAsync()
{
cancellationToken.ThrowIfCancellationRequested();
return UniTask.FromException<bool>(exception);
}
public UniTask DisposeAsync()
{
return default;
}
}
}
}